Results 1 to 8 of 8

Thread: [RESOLVED] [2005] Graphics Object

  1. #1

    Thread Starter
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    Resolved [RESOLVED] [2005] Graphics Object

    Right now I'm drawing multiple things to a form using a graphics object. Because of this, I've got a bit of flickering. I figure I can get rid of the flickering if I can create an offscreen graphics object with mostly the same properties as the form one. How can I do this? Thanks.

  2. #2
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: [2005] Graphics Object

    I have heard of people turning on Double Buffering (setting the Double Buffered Property of the Form to True) to resolve this... not sure if it will be in your case, but something to try...

  3. #3

    Thread Starter
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    Re: [2005] Graphics Object

    Sorry, that doesn't work. I figure this'll be pretty easy once I figure out how to make a graphics object.

  4. #4
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: [2005] Graphics Object

    Well I had always read that you should not store a Graphics object outside of the scope of the method that its given to. I even found the link to the article I read that specified that, linked below. You can check out this "Beginners Guide to GDI+" to see if that helps at all...

    http://www.bobpowell.net/beginnersgdi.htm

  5. #5
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: [2005] Graphics Object

    On second look, that article doesnt really go into what you are looking for. I have read methods where you could call InValidate() only on the control or controls that you are drawing in order for it to only have to update those controls.

    I have also found this short article that shows how to use Graphics.FromImage to create a back buffer... this may be similar to what the double buffer property does, but I figured I would put it up anyways...
    http://www.developerfusion.co.uk/show/4668/

  6. #6

    Thread Starter
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    Re: [2005] Graphics Object

    Ok, thanks for the help, I think I can work with the last link you gave.

  7. #7
    No place like 127.0.0.1 eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Location
    Blissful Oblivion
    Posts
    2,306

    Re: [RESOLVED] [2005] Graphics Object

    Try putting these in the load event of your form:
    VB Code:
    1. SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
    2.         SetStyle(ControlStyles.AllPaintingInWmPaint, True)
    Visual Studio 2005 Professional Edition (.NET Framework 2.0)
    ~ VB .NET Links: Visual Basic 6 to .NET Function Equivalents (Thread) | Refactor! (White Paper) | Easy Control for Wizard Forms | Making A Proper UI For WinForms | Graphics & GDI+ Tutorial | Websites For Free Icons
    ~ QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rich Cook

    ~ eyeRmonkey.com

  8. #8
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: [RESOLVED] [2005] Graphics Object

    I think what you're looking for is some explanation of how to draw to a memory location, and then to set that onto the screen to avoid flickering.

    If you post some example of what you're drawing and when it flickers, we can probably show you how to avoid it. Usually it would involve drawing to a Bitmap object instead of on the form, and then either calling DrawImage to put that on the form, or simply setting the form's backgroundimage to that bitmap.

    VB Code:
    1. Dim Bm As New Bitmap(Me.Width, Me.Height) 'Creates a new memory bitmap object with the form's height/width as the size
    2. Dim gr As Graphics = Graphics.FromImage(Bm)
    3.  
    4. 'Your drawing code here, i.e,
    5. gr.Drawline(Pens.Blue,0,0,40,40)
    6. 'And then after you're finished the drawings
    7.  
    8. Me.BackgroundImage = Bm

    Bill
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

Posting Permissions

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



Click Here to Expand Forum to Full Width