-4

有问题controls.add(pic)

private void blockRoadMouseMove(System.Object sender,
          System.Windows.Forms.MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Left)
        {
            if (Control.ModifierKeys == Keys.Control)
            {
                int yo = this.Location.Y;
                int startx = this.Left;
                int cx = startx;
                int mo = e.X + this.Left - clickOffsetX;

                DrawingControl.SuspendDrawing(mainPic);
                mainPic.SuspendLayout();
                blockRoad pic = new blockRoad(mainPic);
                DrawingControl.SuspendDrawing(pic);

                for (int t = cx; t < mo; t += 20)
                {
                    pic.setChar(this.Image, t, yo);
                }
                mainPic.ResumeLayout();
                DrawingControl.ResumeDrawing(mainPic);
            }
        }
    }    

我用那个

class DrawingControl
    {
        [DllImport("user32.dll")]
        public static extern int SendMessage(IntPtr hWnd, Int32 wMsg, bool wParam, Int32 lParam);

        private const int WM_SETREDRAW = 11;

        public static void SuspendDrawing(Control parent)
        {
            SendMessage(parent.Handle, WM_SETREDRAW, false, 0);
        }

        public static void ResumeDrawing(Control parent)
        {
            SendMessage(parent.Handle, WM_SETREDRAW, true, 0);
            parent.Refresh();
        }
    }

问题是在一个位置添加许多(图片)下一个位置添加许多..下一个添加...

在(每个)一个位置添加许多图片我想在每个位置添加(一个)图片

4

1 回答 1

0

如果blockRoad不在这个位置(添加),我通过添加(检查)解决了这个问题

for (int t = cx; t < mo; t += 20)
{
    Control c = pic.GetChildAtPoint(new Point(cx, y));

    if (c == null)
    {
        pic.setChar(this.Image, t, yo);
        pic.Controls.Add(pic);
    }
}

如果有其他解决方案,我希望我知道谢谢

于 2013-01-16T18:47:55.043 回答