我是使用Windows窗體和C#繪製任何東西的初學者,我有一個問題(我無法在互聯網上找到答案)。所以這裏是我的問題:我試圖建立簡單的應用程序,我使用trackbar來操縱矩形的大小。在Windows窗體中繪圖
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方法?有什麼建議麼?先謝謝你。
非常感謝,它的工作:) –
不要忘記接受爲答案! :-) –