0

我想在两点之间画一条线:

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

假设我有2 个面板,想从 to 画Panel1线Panel2

解释:

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)
4

2 回答 2

0

在窗体的事件中使用Graphics.DrawLine方法。Paint

于 2012-07-24T13:31:00.480 回答
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);


    }
于 2012-07-24T13:43:59.590 回答