主要思路有3个步骤
1.获取当前的坐标
2.创建实体,插入指定的TextBox控件
private void fMain_MouseDown(object sender, MouseEventArgs e)
{
TextBox ztxt = new TextBox();
//设定他的名称和Text属性,以及产生的位置
ztxt.Left = e.X;
ztxt.Top = e.Y;
ztxt.Name = "zTxt" + counter;
ztxt.Text = "内容" + counter;
ztxt.ContextMenuStrip = zcms;
ztxt.MouseDown += ztxt_MouseDown;
//在窗体中显示此文本框
this.Controls.Add(ztxt);
counter++;
}
3.右键鼠标移除
private void ztsmdel_Click(object sender, EventArgs e)
{
if (curctl != null) { this.Controls.Remove(curctl); }
}
实现的效果如下