110,534
社区成员
发帖
与我相关
我的任务
分享
foreach (Control c in this.tb_ShowBusbar .Controls )
{
if (c is TabPage &&c.Name.Equals("tp_BusbarInformation1"))
{
Graphics graphics = c.CreateGraphics();
Pen myPen = new Pen(Color.Black, 3);
graphics.DrawLine(myPen, 0, 0, 200, 200);
Label ll = new Label();
ll.Text = "ddd";
c.Controls.Add(ll);
}
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
var o = new Label();
o.Text = "ABCDEFG";
o.Paint += new PaintEventHandler(o_Paint);
Controls.Add(o);
}
void o_Paint(object sender, PaintEventArgs e)
{
var c = sender as Control;
var g = e.Graphics;
g.DrawLine(Pens.Red, 0, 0, c.Width, c.Height);
}
}
private void button1_Click(object sender, EventArgs e)
{
Panel p = new Panel();
p.Name = "pp";
// p.Location = new Point(0,0);
p.Dock = DockStyle.Fill ;
this.Controls.Add(p);
}
private void button2_Click(object sender, EventArgs e)
{
foreach (Control c in this.Controls)
{
if (c is Panel &&c.Name.Equals("pp"))
{
Graphics graphics = c.CreateGraphics();
Pen myPen = new Pen(Color.Black, 3);
graphics.DrawLine(myPen, 200,0, 200, 200);
// Label ll = new Label();
// ll.Text = "ddd";
// c.Controls.Add(ll);
}
}
}