我设计了几个自定义控件,分别用于画多边形,画线等等。我希望在点击某个按钮的时候它能够显示出来,我试过拖拉控件的方法,但是它们之间总是相互影响,所以我想在点击某个按钮后,某个控件就开始初始化,另一个自定义控件就被注销。如何实现呢,请各位高手帮帮忙吧
我将自定义控件放到按钮点击事件中,但是控件没有显示出来
像这样:
private void 距离ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (this.drawLineTools1 == null)
{
// MessageBox.Show("dsaf");
this.drawLineTools1 = new 空间分析.DrawLineTools(this.pictureBox1);
this.drawLineTools1.Location = new System.Drawing.Point(307, 4);
this.drawLineTools1.Name = "drawLineTools1";
this.drawLineTools1.Size = new System.Drawing.Size(159, 24);
this.drawLineTools1.TabIndex = 11;
this.splitContainer1.Panel1.Controls.Add(this.drawLineTools1);
this.drawLineTools1.Visible = true;
if(this.drawPolygon1!=null)
this.drawPolygon1.Visible = false;
}
}
但是该自定义控件drawLineTools1没有显示出来。但肯定的是它的确生成了,只是没显示出来,帮帮我吧
控件 C# GDI+
------解决方案--------------------
WebForm还是WinForm?重点不在于你如何加载,重点在于你的控件初始化属性写得对不对?
------解决方案--------------------
你可以写,例如(假设是用来测试自定义MyLine控件的按钮)
void button1_click(object sender, EventArgs e)
{
container.Controls.Clear();
var shape= new MyLine();
container.Controls.Add(shape);
}