dcsimg
Results 1 to 4 of 4

Thread: Graphics not working?

  1. #1

    Thread Starter
    Addicted Member NinjaNic's Avatar
    Join Date
    Dec 2013
    Location
    Earth
    Posts
    230

    Graphics not working?

    Me.CreateGraphics.DrawRectangle (or any other shape) doesn't work! Nothing shows up no matter what color I use! How do I fix this?
    Is the form's background covering up the shape?

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,601

    Re: Graphics not working?

    NEVER call CreateGraphics. If you want to draw on a control then ALWAYS use that control's Paint event. For some examples, follow the CodeBank link in my signature and check out my threads on Drawing. There are three of them if I remember correctly.

  3. #3

    Thread Starter
    Addicted Member NinjaNic's Avatar
    Join Date
    Dec 2013
    Location
    Earth
    Posts
    230

    Re: Graphics not working?

    Ok, thanks, but why should I never call Create Graphics?

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,601

    Re: Graphics not working?

    Quote Originally Posted by NinjaNic View Post
    Ok, thanks, but why should I never call Create Graphics?
    A lot of people do call CreateGraphics in GDI+ examples because what they're trying to exemplify is the USING of a Graphics object. Unfortunately, a lot of people are misled into believing that that's what they should do in their own code too, which it is not. In Windows Forms, a control gets repainted often. Each time a repaint occurs, any pixels drawn on the control are cleared and new ones drawn. If you call CreateGraphics then you'll draw something onto the control but it will be erased on the next repaint. By drawing on the Paint event you ensure that your drawing gets reinstated each time it is erased. I actually explain that in at least one of those threads so maybe you should do as instructed first and then ask questions afterwards if you still have any outstanding.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width