By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,815 Members | 1,151 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,815 IT Pros & Developers. It's quick & easy.

how to paint 1px by 1px clear image on windows form

P: n/a
I'm painting images onto a windows form using this method:

e.Graphics.DrawImageUnscaled(m_ItemImage, x, y)

every time I select a product. However, some products don't have an image
so when a user selects a different product from a list and that product
doesn't have an image, I need to clear the image from the previous product
that was painted onto the form.

I was thinking of creating a clear image and using the DrawImageUnscaled
method, but if anyone has a better idea, I'm all ears.

Can anyone make some good recommendations.

Thanks.

--
mo*******@nospam.com
Nov 20 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
"moondaddy" <mo*******@nospam.com> wrote in message
news:Ou**************@tk2msftngp13.phx.gbl...
I'm painting images onto a windows form using this method:

e.Graphics.DrawImageUnscaled(m_ItemImage, x, y)

every time I select a product. However, some products don't have an image
so when a user selects a different product from a list and that product
doesn't have an image, I need to clear the image from the previous product
that was painted onto the form.

I was thinking of creating a clear image and using the DrawImageUnscaled
method, but if anyone has a better idea, I'm all ears.

Can anyone make some good recommendations.

Thanks.


Personally, I would use a PictureBox and change Visible to False when it is
not needed, i.e. there is no image to show. But you could always use
e.Graphics.DrawRectangle and erase it, if you continue down the path you are
on.

Best Regards,

Andy

".NET or .DIE"
Nov 20 '05 #2

P: n/a
Hi,

It seems that you are painted the picture in the OnPaint event.
If so I think we can just do not call the
e.Graphics.DrawImageUnscaled(m_ItemImage, x, y) method, so that there will
be no picture drawn on the form. If you want to display any thing to to
indicate that the product is of no pciture, we can just paint it on the
form, e.g. a predefined picture or some text.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #3

P: n/a
OK I'll look into it.

--
mo*******@nospam.com
""Peter Huang"" <v-******@online.microsoft.com> wrote in message
news:aE**************@cpmsftngxa10.phx.gbl...
Hi,

It seems that you are painted the picture in the OnPaint event.
If so I think we can just do not call the
e.Graphics.DrawImageUnscaled(m_ItemImage, x, y) method, so that there will
be no picture drawn on the form. If you want to display any thing to to
indicate that the product is of no pciture, we can just paint it on the
form, e.g. a predefined picture or some text.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #4

P: n/a
Thanks Andy, The reason I need to draw the image on the form and not a
picturebox is because the images vary in size and dimension and the
picturebox resized the image into the size of the picturebox which deforms
the image.

--
mo*******@nospam.com
"Andy Becker" <x@x.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
"moondaddy" <mo*******@nospam.com> wrote in message
news:Ou**************@tk2msftngp13.phx.gbl...
I'm painting images onto a windows form using this method:

e.Graphics.DrawImageUnscaled(m_ItemImage, x, y)

every time I select a product. However, some products don't have an image so when a user selects a different product from a list and that product
doesn't have an image, I need to clear the image from the previous product that was painted onto the form.

I was thinking of creating a clear image and using the DrawImageUnscaled
method, but if anyone has a better idea, I'm all ears.

Can anyone make some good recommendations.

Thanks.
Personally, I would use a PictureBox and change Visible to False when it

is not needed, i.e. there is no image to show. But you could always use
e.Graphics.DrawRectangle and erase it, if you continue down the path you are on.

Best Regards,

Andy

".NET or .DIE"

Nov 20 '05 #5

P: n/a
Hi

I look forward to your reply. If you have any concern on this issue,please
feel free to post here and I will work on it with you.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #6

P: n/a
Thanks Peter, That worked for me.

Now I'm changing the form around a bit and most of the form is covered by a
tab control. So now I need to paint the image on the tab control. How
would I do that?

--
mo*******@nospam.com
""Peter Huang"" <v-******@online.microsoft.com> wrote in message
news:aE**************@cpmsftngxa10.phx.gbl...
Hi,

It seems that you are painted the picture in the OnPaint event.
If so I think we can just do not call the
e.Graphics.DrawImageUnscaled(m_ItemImage, x, y) method, so that there will
be no picture drawn on the form. If you want to display any thing to to
indicate that the product is of no pciture, we can just paint it on the
form, e.g. a predefined picture or some text.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #7

P: n/a
Hi,

Do you mean the tabcontrol or the tabpage control?
For the tabcontrol we can create a graphics based on the hwnd of the
tabcontrol, but the tabpage is on the tabcontrol, the picture will be
coverred by the tabpage.
Dim hwnd As New IntPtr
hwnd = Me.TabControl1.Handle
' Create new graphics object using handle to window.
Dim newGraphics As Graphics = Graphics.FromHwnd(hwnd)
newGraphics.DrawImage(New
System.Drawing.Bitmap("c:\test\TestPIC\a.bmp"), 0, 0)

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.