473,320 Members | 1,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to resize the bitmap used for Paint event

This is what I do in a PictureBox New:
b1 = New Drawing.Bitmap(Width, Height, Me.CreateGraphics())

g1 = Graphics.FromImage(b1)

Someplace I do

g1.DrawString.........

Then in Paint I do:

e.Graphics.DrawImage(b1, 0, 0)

Do I have to do something in Dispose??

What should I do if the Box is resized??

Thanks

Cal


Nov 20 '05 #1
5 1991
" active" <ac****@REMOVEa-znet.com> schrieb
This is what I do in a PictureBox New:
b1 = New Drawing.Bitmap(Width, Height, Me.CreateGraphics())

g1 = Graphics.FromImage(b1)

I guess you declared g1 and b1 at class level? (a field in the class)

In Sub New I'd probably write

dim g as graphics
g = me.creategraphics
b1 = New Drawing.Bitmap(Width, Height, g)
g.dispose '<- dispose here
g1 = Graphics.FromImage(b1)
'...

Someplace I do

g1.DrawString.........

Then in Paint I do:

e.Graphics.DrawImage(b1, 0, 0)

Do I have to do something in Dispose??
I'd call g1.dispose and b1.dispose.
What should I do if the Box is resized??


I'd call g1.dispose, b1.dispose and recreate the bitmap. So, the Bitmap
creating lines should be a separate proc called from the ctor and in
OnResize.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html


Nov 20 '05 #2
I realize that the quick test I had did seemed to work but it was not
correct.
I have a usercontrol containing a picturebox that I want to draw on.
What happens is I'm drawing on the UserControl instead.



I guess you declared g1 and b1 at class level? (a field in the class)

In Sub New I'd probably write

dim g as graphics
g = me.creategraphics
can't use g1 here? Why do we need g? b1 = New Drawing.Bitmap(Width, Height, g)
I don't understand why dispose and then get a new one.
What is this for?? g.dispose '<- dispose here
g1 = Graphics.FromImage(b1)
'...
What should I do if the Box is resized??


I'd call g1.dispose, b1.dispose and recreate the bitmap. So, the Bitmap
creating lines should be a separate proc called from the ctor and in
OnResize.


recreate the graphics in the bitmap is not possible. Think of Photoshop and
the user resizes after drawing.
Thanks for helping,
Cal
Nov 20 '05 #3
" active" <ac****@REMOVEa-znet.com> schrieb
I realize that the quick test I had did seemed to work but it was
not correct.
I have a usercontrol containing a picturebox that I want to draw
on. What happens is I'm drawing on the UserControl instead.


Then you can paint in the Picturebox' paint event.

An alternative is to derive your own class from the Picturebox class and
override OnPaint - but currently this does not make the difference.
I guess you declared g1 and b1 at class level? (a field in the
class)

In Sub New I'd probably write

dim g as graphics
g = me.creategraphics


can't use g1 here? Why do we need g?


It was _you_ who created a new Graphics object. In your first posting you
wrote

b1 = New Drawing.Bitmap(Width, Height, Me.CreateGraphics())

I changed this and assigned the return value of Me.CreateGraphics to the
variable to be able to call the Dispose method afterwards.

b1 = New Drawing.Bitmap(Width, Height, g)


I don't understand why dispose and then get a new one.
What is this for??
g.dispose '<- dispose here
g1 = Graphics.FromImage(b1)
See comment above: You also created two Graphics objects. I guess you did it
because you wanted this for the reason described in the documentation for
the constructor when passing a graphics object: The resolution of the
graphics object is applied to the bitmap.
What should I do if the Box is resized??


I'd call g1.dispose, b1.dispose and recreate the bitmap. So, the
Bitmap creating lines should be a separate proc called from the
ctor and in OnResize.


recreate the graphics in the bitmap is not possible. Think of
Photoshop and the user resizes after drawing.


What does this mean? You can copy the old Bitmap into the new Bitmap if you
don't want to loose the content.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
Nov 20 '05 #4
Then you can paint in the Picturebox' paint event. I had figured that out and it makes sense and works OK.


dim g as graphics
g = me.creategraphics


can't use g1 here? Why do we need g?


It was _you_ who created a new Graphics object. In your first posting you
wrote

b1 = New Drawing.Bitmap(Width, Height, Me.CreateGraphics())

I changed this and assigned the return value of Me.CreateGraphics to the
variable to be able to call the Dispose method afterwards.

Got it! Thanks
> What should I do if the Box is resized??

recreate the graphics in the bitmap is not possible. Think of
Photoshop and the user resizes after drawing.


What does this mean? You can copy the old Bitmap into the new Bitmap if

you don't want to loose the content.
Sounds good to me. thanks


Thank a lot
Cal
Nov 20 '05 #5
* " active" <ac****@REMOVEa-znet.com> scripsit:
This is what I do in a PictureBox New:
b1 = New Drawing.Bitmap(Width, Height, Me.CreateGraphics())

g1 = Graphics.FromImage(b1)

Someplace I do

g1.DrawString.........

Then in Paint I do:

e.Graphics.DrawImage(b1, 0, 0)

Do I have to do something in Dispose??
You will have to dispose 'g1'.

\\\
g1.Dispose()
///
What should I do if the Box is resized??


Who knows what you want to do?

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Joao Santa Barbara | last post by:
Hi all i need to resize a background image in a mdi parent form ? how can i do this i have tryed to do in the resize event, and, in the overload background paint, bla, bla .. and it didn´t show...
0
by: Dave Veeneman | last post by:
I'm creating a custom control that uses the OnPaint event to paint a graphic. The graphic needs to resize itself when the control is resized. Right now, I'm trapping the Resize event to trigger the...
8
by: Ian Stiles | last post by:
If you have "Show window contents while dragging" turned on (Right-click desktop, Appearance, Effects) then you get horrible flashing and flickering on a CSharp form when the form hosts a...
7
by: Dennis | last post by:
I am trying to implement drawing on a bitmap and using bitblt to transfer it to the control graphics object in the paint event. It seems to draw on the bitmap ok but doesn't get transferred to the...
15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
0
by: AlVis1515 | last post by:
We had a VB6 program that was used to take a scanned signature image as a set of screen coordinates. The VB6 program then converted this into a bitmap file which we used to embed the signature...
15
by: Hamed | last post by:
Have I posted the message to wrong newsgroup? Or Does the question is so much strage? Would someone please kindly direct me to a true newsgroup or resource? Best Regards Hamed
6
by: \Frank\ | last post by:
I trying to learn what a Bitmap is. Not a Managed Bitmap Object but one that, for example, comes from the clipboard with CF_BITMAP. I'm guessing that a CompatableBitmap is an array of indices...
1
by: martinsmith160 | last post by:
Hi all I am trying to create a level builder tool for a final year project and im having some problems drawing. I have placed a picture box within a panel so i can scroll around the image which is...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.