Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. New to C# - dumb question about how to reference a Form

New to C# - dumb question about how to reference a Form

Scheduled Pinned Locked Moved C#
graphicsquestioncsharplamphelp
1 Posts 1 Posters 12 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Daniel Davis 2024
    wrote on last edited by
    #1

    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);
    

    }

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups