New to C# - dumb question about how to reference a Form
-
So I'm pretty new to C#. I've created a project that's pretty basic. A single timer control, a text box. The timer control changes the color of the text depending on certain contexts. I would like to display an image on the form at a certain point, and a black rectangle then covers the image and changes in opacity to "fade in" the image to view. I've got the code that puts the image onto the form and it works pretty well (I used CreateGraphics at one point but it was far too slow). The only problem is that I would like it to paint the image during the timer event, not at form load. So here's my completely dumb question, and since I'm pretty new I'm sure it's an easy answer but I just couldn't figure it out- The code calls a method called LampPaint, which is supposed to draw the lamp to the screen, and the method works great when the form loads. ReverseCount is a global variable that determines the opacity of the rectangle based on the timer count.
this.Paint += this.LampPaint;
this.Update();The problem is that while the timer is running, "this" ceases to reference the form and is (I think) referencing this timer itself. So if the form is called MainScreen, what do I change "this" to in order to directly reference the form to paint to? Again, my deepest apologies if this is a dumb question. Oh yes, this is the method itself.
private void LampPaint(object form1, PaintEventArgs e)
{var g = e.Graphics; Bitmap LampImage = \_TestProgram.Properties.Resources.Lamp; g.DrawImage(LampImage, 0, 400, 500, 600); Brush selBrush = new SolidBrush(Color.FromArgb(Global.ReverseCount, 0, 0, 0)); g.FillRectangle(selBrush, 0, 400, 500, 700);
}