• 0

[vb.net] imagesize


Question

i have a panel with a background image with a label on top and i need to change the panel size several times and i need to stretch the image in order to have a good aspect. I was thinking about changing the image size everytime i resize the control, i don't know if this is the best way to do it... but first i need to know how to change the image size.

dim ima as image
ima.width=panel1.width

tried this but it says that ima.width is read only

Link to comment
Share on other sites

10 answers to this question

Recommended Posts

  • 0

well if you use a image control you can just set stretch and change the size of the image control.... im not sure if that control is in .net, i know its in vb6.

-try it.

Link to comment
Share on other sites

  • 0

I haven't tried this so I don't know if it would work but you try casting the Image object as a Bitmap object (or just use a Bitmap object in the first place) and using the SetResoloution function.

C# Example (sorry, I don't know Visual Basic)

 Image ima = GetImage();

  Bitmap bmp = new Bitmap( ima );   // Preferred method
//  Bitmap bmp = (Bitmap)ima;        // Casting method

  bmp.SetResoloution( panel1.width, panel1.height );

Again, I don't know if it would work.

Edited by virtorio
Link to comment
Share on other sites

  • 0

Why not try to make a user control that inherits from the Panel control and override the OnPaint method to draw the image yourself? When the control is resized, redraw the image.

Link to comment
Share on other sites

  • 0

hmmm.. it seems i can't do that... because i need a label on top of the image... and as we all know if i set the label background to transparent it will display the background of the panel or of the form.

Link to comment
Share on other sites

  • 0

That only happens if your adding the label to the form, not the bitmap. Make sure you are doing PictureBox.Controls.Add(Label) instead of Form.Controls.Add(Label).

Dan

EDIT: Though the best/fastest solution is to use OnPaint/Paint event handler.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.