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

  • Thread starter Thread starter moondaddy
  • Start date Start date
M

moondaddy

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.
 
moondaddy said:
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"
 
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.
 
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.
 
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.
 
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?
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top