我是使用 Windows 窗体和 C# 绘制任何东西的初学者,我有一个问题(我无法在互联网上找到答案)。所以这是我的问题:我正在尝试构建简单的应用程序,我使用轨迹栏来操纵矩形的大小。
namespace Drawing
{
public partial class Form1 : Form
{
int size = 10;
public Form1()
{
InitializeComponent();
CenterToScreen();
}
protected override void OnPaint(PaintEventArgs pe)
{
Graphics g = pe.Graphics;
Rectangle rect = new Rectangle(50,50, size,size);
LinearGradientBrush IBrush = new LinearGradientBrush(rect, Color.Green, Color.Yellow,
LinearGradientMode.BackwardDiagonal);
g.FillRectangle(IBrush, rect);
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
}
private void trackBar1_Scroll(object sender, EventArgs e)
{
size = trackBar1.Value;
// I was trying to put here OnPaint method but it doesnt work.
}
}
}
而且我只是不知道当 tracBar1_Scroll 发生时如何调用 OnPaint 方法?有什么建议么?先感谢您。