Results 1 to 9 of 9

Thread: Persisting Graphics{Resolved}

  1. #1

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Persisting Graphics{Resolved}

    I have a project I've been working on and it consists of working with graphics.

    The only problem I have is when the graphics show up on the form; if I minimize it or another window comes over top of my projects form, it erases the graphics.

    I know I might of not explained this well enough or it might not make sense but I'm not sure how to explain it. So Can anyone please give me a solution?

    Also I posted in the other forum and got an answer in VB6 when i need it in VB.NET
    anyways they said that the auto redraw property of the form should be set to true.

    What would the auto redraw property of a form be in VB.NET?
    Last edited by System_Error; Apr 28th, 2004 at 05:29 PM.

  2. #2
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hi.

    There is no autoredraw in NET...
    If you're painting directly on the form, using the CreateGraphics then that's why your graphics disappear. That is only drawn to the surface once, so it will be removed on the next redraw.

    To keep the graphics, you need to paint it in the Paint event of the form (or whatever object you're drawing on). Then draw to e.Graphics.
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  3. #3
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    Draw the graphics onto a bitmap object. And then set the form's image property = the bitmap.

    Et voila, persistent graphics.

    It took me ages to work out how to do that and I hated .net because it had no autoredraw. But it actually promotes better programming practices imo.
    I don't live here any more.

  4. #4

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111
    Thanx. That was a huge help.

  5. #5
    Fanatic Member Ruku's Avatar
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    655

    Re: Persisting Graphics{Resolved}

    Draw the graphics onto a bitmap object. And then set the form's image property = the bitmap.
    got samples?

    man, I got the same problem, me brain's about to blow!



    edit: got everything fixed up... but I don't have as much flexibility over doing graphics...

    can't draw a string directly to the bitmap...
    Last edited by Ruku; Dec 5th, 2005 at 09:43 PM.

    Using VB.NET 2005/.NET 2.0, NetBeans IDE 5, Fujitsu Cobol85,
    Website: http://DreamForgery.com

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

    Re: Persisting Graphics{Resolved}

    VB Code:
    1. Dim bm As New Bitmap(Me.Size.Width, Me.Size.Height)
    2.         Dim gr As Graphics
    3.         gr = Graphics.FromImage(bm)
    4.         gr.FillRectangle(SystemBrushes.Control, 0, 0, Me.Size.Width, Me.Size.Height)
    5.         gr.DrawEllipse(Pens.Black, 0, 0, 100, 50)
    6.         Me.BackgroundImage = bm

    The fillREct is there so you don't have a transparent background on repaint..

    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.

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Persisting Graphics{Resolved}

    Quote Originally Posted by Ruku
    can't draw a string directly to the bitmap...
    Wouldn't you just call the DrawString method of the Graphics object?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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

    Re: Persisting Graphics{Resolved}

    He's right, the DrawString method will do just that, however, if you are wanting the app to have the look and feel of the rest of the OS, you can run into much more code. You'll need to take into consideration the size and style of fonts being used by the user in order to do this well. You can get the font as easily as using Me.Font inside your form class, and the dimensions of the finished product by using the MeasureString method, though some have mentioned certain characters don't measure correctly.

    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.

  9. #9
    Fanatic Member Ruku's Avatar
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    655

    Re: Persisting Graphics{Resolved}

    yeah, I got everything fixed up! I figured how to use the graphics object onto the bitmap object...

    Using VB.NET 2005/.NET 2.0, NetBeans IDE 5, Fujitsu Cobol85,
    Website: http://DreamForgery.com

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