尝试下面的东西,它是在c#中,但你可以很容易地将其转换为vb.net,并且你需要根据面板位置调整x,y坐标。
private void Form1_Load(object sender, EventArgs e)
{
this.Controls.Add(new Panel{Left = 10, Top = 10,Width = 50,Height = 50, BackColor = Color.Blue});
this.Controls.Add(new Panel {Left = 100, Top = 100,Width = 50,Height = 50, BackColor = Color.Blue});
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g;
g = e.Graphics;
Pen myPen = new Pen(Color.Red);
myPen.Width = 1;
g.DrawLine(myPen, 12, 12, 45, 65);
g.DrawLine(myPen, 100, 100, 45, 65);
}
为什么你有两个面板?你想要在面板内还是在面板所在的窗体中绘制线条? – Charlie 2012-07-24 14:53:09