我正在尝试调用panel1绘制方法以用橙色线重新绘制面板(它以蓝色线启动)。
我已经尝试过 invalidate()、update() 和 refresh(),但似乎没有任何东西可以调用 panel1 的绘制事件...
绘画事件处理程序已添加到 panel1:
this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint);
有人可以帮忙吗?
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Form1 testForm = new Form1();
Application.Run(testForm);
testForm.drawNewLine();
}
}
public partial class Form1 : Form
{
bool blueLine = true;
bool orangeLine = false;
public Form1()
{
InitializeComponent();
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
if (blueLine == true)
{
Pen bluePen = new Pen(Color.Blue, 3);
g.DrawLine(bluePen, 30, 50, 30, 250);
}
else if (orangeLine == true)
{
Pen orangePen = new Pen(Color.Orange, 3);
g.DrawLine(orangePen, 30, 50, 30, 250);
}
g.Dispose();
}
public void drawNewLine()
{
blueLine = false;
orangeLine = true;
//panel1.Invalidate();
//panel1.Update();
panel1.Refresh();
}
}