C# 为什么拖放时面板上的图片之间会出现空白?
所以,我尝试将图片框拖放到一个面板上,这个面板可以正常工作,但是框之间有一些空白,我不明白为什么会发生这种情况 单击下面的图片,您将能够看到我的情况示例,以及使用面板和图像框上事件的代码-DragDrop、DragOver和MouseDownC# 为什么拖放时面板上的图片之间会出现空白?,c#,visual-studio,C#,Visual Studio,所以,我尝试将图片框拖放到一个面板上,这个面板可以正常工作,但是框之间有一些空白,我不明白为什么会发生这种情况 单击下面的图片,您将能够看到我的情况示例,以及使用面板和图像框上事件的代码-DragDrop、DragOver和MouseDown private void panelMap\u DragOver(对象发送方,DragEventArgs e) { e、 效果=DragDropEffects.All; } 私有void pictureBox1\u MouseDown(对象发送方,Mou
private void panelMap\u DragOver(对象发送方,DragEventArgs e)
{
e、 效果=DragDropEffects.All;
}
私有void pictureBox1\u MouseDown(对象发送方,MouseEventArgs e)
{
if(!runningSimulation)
{
pictureBox1.DoDragDrop(pictureBox1.Image,DragDropEffects.Copy);
dragTypeOne=真;
}
}`私有void panelMap_DragDrop(对象发送方,DragEventArgs e)
{
点游标=点到客户端(游标位置);
点绘制点=新点();
//找出交叉点落在哪个单元格上
确定塞尔(e);
drawPoint=map.Cells[selectedCell-1]。位置;
//移动十字路口
if(e.Effect==DragDropEffects.Move)
{
foreach(地图中的交叉路口)
{
if(cr.Location==mouseDown&&!map.Cells[selectedCell-1].take)
{
cr.位置=提取点;
//cr.Pb_Background.Location=绘图点;
cr.Pb_.Location=绘图点;
map.Cells[selectedCell-1].take=true;
map.Cells[selectedCell-1]。交叉=map.Cells[firstSelection-1]。交叉;
单元格[firstSelection-1].take=false;
单元格[firstSelection-1]。交叉=null;
//grid.checkneights(selectedCell-1);
对于(int i=0;i
对不起。我已经编辑过了,对不起。我已经编辑过了。
private void panelMap_DragOver(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.All;
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (!runningSimulation)
{
pictureBox1.DoDragDrop(pictureBox1.Image, DragDropEffects.Copy);
dragTypeOne = true;
}
}` private void panelMap_DragDrop(object sender, DragEventArgs e)
{
Point cursor = PointToClient(Cursor.Position);
Point drawPoint = new Point();
//Finding out which cell the crossing is dropped on
determineCell(e);
drawPoint = map.Cells[selectedCell - 1].Location;
//Moving the crossing
if (e.Effect == DragDropEffects.Move)
{
foreach (Crossing cr in map.Crossings)
{
if (cr.Location == mouseDown && !map.Cells[selectedCell - 1].Taken)
{
cr.Location = drawPoint;
// cr.Pb_Background.Location = drawPoint;
cr.Pb_Transparent.Location = drawPoint;
map.Cells[selectedCell - 1].Taken = true;
map.Cells[selectedCell - 1].Crossing = map.Cells[firstSelection - 1].Crossing;
map.Cells[firstSelection - 1].Taken = false;
map.Cells[firstSelection - 1].Crossing = null;
//grid.CheckNeighbours(selectedCell - 1);
for (int i = 0; i < map.Cells.Count; i++)
{
if (map.Cells[i].Taken)
{
map.CheckNeighbours(i);
}
}
}
}
}
else if (!map.Cells[selectedCell - 1].Taken)
{
map.Cells[selectedCell - 1].Taken = true;
PictureBox pb_b = new PictureBox();
pb_b.Height = panelMap.Height / 3;
pb_b.Width = panelMap.Width / 4;
pb_b.SizeMode = PictureBoxSizeMode.StretchImage;
pb_b.BackColor = Color.Transparent;
pb_b.MouseDown += new MouseEventHandler(Mouse_Down);
pb_b.Image = (Image)e.Data.GetData(DataFormats.Bitmap);
//Added transparent layer
PictureBox pb_t = new PictureBox();
pb_t.Size = pb_b.Size;
pb_t.MouseDown += new MouseEventHandler(Mouse_Down);
//Which crossing will be dragged
if (dragTypeOne)
{
System.Drawing.Graphics formGraphics = this.CreateGraphics();
Cross_Shaped cr = new Cross_Shaped(drawPoint, pb_b, pb_t);
pb_b.Location = cr.Location;
pb_b.Tag = cr;
pb_t.Tag = cr;
map.AddCrossing(cr);
map.Cells[selectedCell - 1].Crossing = cr;
pb_b.Image = CTF.Properties.Resources.crossing;
}
this.Controls.Add(pb_b);
this.Controls.Add(pb_t);
pb_t.BringToFront();
pb_b.Location = drawPoint;
pb_b.Parent = panelMap;
pb_t.Parent = pb_b;
map.CheckNeighbours(selectedCell - 1);
}
}`