I was working a program where a rectangle is drawn inside a label through a paint event. Then with a button click event I want to redraw the inside of label now having the original rectangle and a new one that is .TranslateTransform some some input. Now to the problem: I was able to create the new original and the copy but if I press the button then I get a copy of the copy. I thought I could fix this if before the redrawing I use label.Refresh() or .Invalidate() but now I can't even get a single copy.
Thanks in advance for the help. Here is the code:
public int x, y;
public float p, q;
Graphics g;
SolidBrush brush1 = new SolidBrush(Color.Green);
public Form1()
{
InitializeComponent();
}
private void label5_Paint_1(object sender, PaintEventArgs e)
{
g = e.Graphics;
g.FillRectangle(brush1, 50, 50, 100, 50);
}
private void shift(object sender, PaintEventArgs e)
{
string a, b;
a = textBox1.Text;
x = int.Parse(a);
b = textBox2.Text;
y = int.Parse(b);
var g = e.Graphics;
Brush br = new SolidBrush(Color.DarkOrange);
g.TranslateTransform(x, y);
g.FillRectangle(br, 50, 50, 100, 50);
}
private void button1_Click(object sender, EventArgs e)
{
label5.Invalidate();
label5.Paint += new PaintEventHandler(shift);
}
private void resize(object sender, PaintEventArgs e)
{
string c, d;
c = textBox3.Text;
p = float.Parse(c);
d = textBox4.Text;
q = float.Parse(d);
var g = e.Graphics;
Brush br = new SolidBrush(Color.DarkOrange);
g.ScaleTransform(p, q);
g.FillRectangle(br, 50, 50, 100, 50);
}
private void button2_Click(object sender, EventArgs e)
{
label5.Invalidate();
label5.Paint += new PaintEventHandler(resize);
}