【问题标题】:parent.controls.add父控件添加
【发布时间】:2012-12-21 18:39:41
【问题描述】:

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();
        }
    }

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

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

【问题讨论】:

  • 对不起,我不明白你想做什么。
  • 我在您的代码中的任何地方都看不到“ctr”。您当前的代码也无法编译(括号问题?)如果您不努力提出问题,您将不会得到任何答案。
  • 我添加了更多代码,我希望现在清楚

标签: c# winforms event-handling


【解决方案1】:

我通过添加解决了这个问题(检查) 如果 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);
    }
}

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-08
    • 1970-01-01
    • 2012-01-11
    • 1970-01-01
    相关资源
    最近更新 更多