resizing an image to fit a control

donnacha

Well-known member
Joined
Feb 27, 2003
Messages
187
Hi folks,
I have a bit map that is created externally that I want to use as a background image for a button but I want the image to be resized to fill the button space no matter how big the button is. I am currently using the following for putting the image in the button, but the image is either cropped or repeated.

Does anybody have an idea how to do this correctly.

Thanks for any help


Dim strm As System.IO.Stream
strm = (Me.GetType.Assembly.GetManifestResourceStream("Project.ButtonStyle1.bmp"))
Me.BackgroundImage = New Bitmap(strm) CType(strm, System.Drawing.Bitmap)
me.Name = "ButtonStyle1"
Me.ImageAlign = ContentAlignment.MiddleCenter
Me.FlatStyle = FlatStyle.Standard
 
Dont use that horrible backgroundimage property!! You will have to make your own button deriving from Button and override the OnPaint event painting your own image. I have done it not only with a button but with a form.
 
Hi aewarnick,
I have solved this problem by using the re-sizing event and to re-scale the image there.

Thanks
 
Back
Top