我需要幫助在WinForm上畫一條線。C#線條繪畫問題
的代碼我現在有大部分被拉斷的MSDN:
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace BouncingBall
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.Invalidate();
}
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
// Insert code to paint the form here.
Pen pen = new Pen(Color.FromArgb(255, 0, 0, 0));
e.Graphics.DrawLine(pen, 10, 10, 300, 200);
}
}
}
目前,這個代碼不畫任何東西。
This Works。你真的有一個事件處理程序將表單的Paint事件連接到你的方法嗎? – vcsjones
並且由於@PaulG不存在,請務必在完成後丟棄該筆 – Justin
嘗試重寫OnPaint方法而不是調用Form1_Paint事件。你顯然沒有把事件聯繫起來。 – LarsTech