dcsimg
Results 1 to 6 of 6

Thread: drawing bitmap for Paint event in separate library

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2016
    Posts
    2

    drawing bitmap for Paint event in separate library

    I have an app that draws engineering diagrams. Right now the diagrams are drawn using the Graphics object in the Paint event for the object it is drawn on. I would like to separate the code for creating the diagram into a separate library.

    I think the best way is to call the library that returns a bitmap, then use the graphics object in the Paint event to draw the bitmap. How can I get the size that the new bitmap needs to be from the arguments passed into the Paint event?

    Am I looking at this wrong?

  2. #2

    Thread Starter
    New Member
    Join Date
    Sep 2016
    Posts
    2

    Re: drawing bitmap for Paint event in separate library

    I think maybe the answer to my question is what ever the size of the area of the control I want to draw on. It could be Me.Width and Me.Height....or a smaller area within that. It's the object that implements the Paint method I should get this from, not the Graphics context.

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    22,961

    Re: drawing bitmap for Paint event in separate library

    You don't pass information about what to paint to the Paint Event. Just declare the BitMap at Form level, draw your graphics on it, then in the Paint Event, you'll be able to access it...

  4. #4
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,744

    Re: drawing bitmap for Paint event in separate library

    Quote Originally Posted by vbcoder2016 View Post
    I think maybe the answer to my question is what ever the size of the area of the control I want to draw on. It could be Me.Width and Me.Height....or a smaller area within that. It's the object that implements the Paint method I should get this from, not the Graphics context.
    You would use the ClientSize property to get the drawing area of the control, or the ClientRectangle. These should define the drawing area of the control, versus Width or Height, which can include borders, or other parts of the control.
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

  5. #5
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,744

    Re: drawing bitmap for Paint event in separate library

    Quote Originally Posted by vbcoder2016 View Post
    I have an app that draws engineering diagrams. Right now the diagrams are drawn using the Graphics object in the Paint event for the object it is drawn on. I would like to separate the code for creating the diagram into a separate library.
    ...
    Of course you can have the code in a separate library, and pass it the graphics object you want to draw on. I often don't put the code doing the drawing in the paint event itself. The paint event just calls the drawing code and passes e.Graphics to it. That way you can use the same code to draw on whatever you want, i.e. the form, or a picturebox, a panel, or a printer, etc...
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    22,961

    Re: drawing bitmap for Paint event in separate library

    Quote Originally Posted by passel View Post
    Of course you can have the code in a separate library, and pass it the graphics object you want to draw on. I often don't put the code doing the drawing in the paint event itself. The paint event just calls the drawing code and passes e.Graphics to it. That way you can use the same code to draw on whatever you want, i.e. the form, or a picturebox, a panel, or a printer, etc...
    Or a bitmap...

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