嘗試下面的東西,它是在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