我需要帮助在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