2012-07-24 61 views
0

我要畫兩個點之間中:Vb.net繪製線兩點

http://i.stack.imgur.com/Yuhsd.gif

比方說,我有2板,想畫線從Panel1Panel2

說明:

dim p1 as new panel 
dim p2 as new panel 

p1.left = 100 
p1.top = 10 
me.controls.add(p1) 

p2.left = 300 
p2.top = 20 
me.controls.add(p2) 

DrawLineBetween(p1,p2) 
+0

爲什麼你有兩個面板?你想要在面板內還是在面板所在的窗體中繪製線條? – Charlie 2012-07-24 14:53:09

回答

0

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


    } 
+0

thanx,作品:) – SSID 2012-07-24 14:04:33