I am beginner in drawing anything using Windows Forms and C# and I have a question(I couldnt have found answer on the internet). So here is my problem : I am trying to build simple application where i use trackbar to manipulate the size of rectangle.
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.
}
}
}
And I just cant figure out how to call OnPaint method when tracBar1_Scroll occurs? Any suggestions? Thank you in advance.