【问题标题】:how to create multi selection如何创建多选
【发布时间】:2013-03-22 06:23:40
【问题描述】:

在一个表单上,我有多个 usercontrols,它们会在每次点击 button 时动态创建。我希望用户能够选择它们以便复制删除等。就像我们用鼠标选择图标,然后删除它们。为此,我创建了另一个用户控件,它是在鼠标位置创建的。我不知道如何绘制该用户控件。到目前为止我的代码:

//method that creates usercontrols
 private void _butttnAddControls_Click(object sender, EventArgs e)
    {
            TControl tcontrol = new TControl();               
            tcontrol.BringToFront();
        }
protected override void OnMouseDown(MouseEventArgs e)
    {
        base.OnMouseDown(e);
        SelectPanel pselect = new SelectPanel();//pselect is the control used to create     the rectangle for selection 
        pselect.Visible = true;
        Point p = PointToClient(Cursor.Position);
        pselect.Location = p;
        pselect.SelectionPanel = true;
        this.Controls.Add(pselect);
    }
     protected override void OnMouseUp(MouseEventArgs e)
    {
        base.OnMouseUp(e);
        pselect.Visible = false;
    }

【问题讨论】:

    标签: c# winforms user-controls controls


    【解决方案1】:

    如果您使用的是 WinForms,您可以使用控件的 DrawToBitmap() 方法来获取您动态创建的用户控件的图像。

    查看此链接了解更多信息Control.DrawToBitmap Method

    然后您可以将所有控件数组绘制到图片框中,并在那里使用鼠标事件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-01
      • 1970-01-01
      • 2023-01-24
      • 1970-01-01
      • 2017-10-10
      • 1970-01-01
      • 2011-08-27
      • 1970-01-01
      相关资源
      最近更新 更多