嘿,我有兩個按鈕(圖 1),我想按行鏈接這些按鈕。我想過用 Class Graphics 和 Pen 畫線,但我試過了,它不起作用。

private void Form1_Paint(object sender, PaintEventArgs e)
{
var lineBegin = new Point(button1.Left button1.Width - 1, button1.Top button1.Height / 2);
var lineEnd = new Point(button2.Left, button2.Top button2.Height / 2);
e.Graphics.DrawLine(Pens.Maroon, lineBegin, lineEnd);
}
uj5u.com熱心網友回復:
這有效

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.DrawLine(
Pens.Blue,
button1.Right 2,
button1.Top button1.Height / 2,
button2.Left - 2,
button2.Top button2.Height / 2);
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/403407.html
標籤:
