469,270 Members | 1,149 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,270 developers. It's quick & easy.

Image stretch or reduced to fit inside button in VB.NET

115 100+
i'm using VB.Net Application program.

i'm creating 64 button dynamically during run time. and from database i'm getting the description, font color, back color and picture path. and if the picture path is not nothing, then i need to display that picture in that button. if picture path is nothing, then need to display the description as button text using font color and back color.

this button values are not loaded only once. using button click Addhandler, each button values keeps on changing each time.

The Code i used to display is

Expand|Select|Wrap|Line Numbers
  1.        For Each c As Control In Controls
  2.             If c.Name = "ItemBtn-" & x Then
  3.                c.Text = ButtonText
  4.                c.ForeColor = System.Drawing.ColorTranslator.FromOle(btnFontColor)
  5.                c.BackColor = System.Drawing.ColorTranslator.FromOle(btnBackColor)
  6.                c.Tag = "ItemPageBtn-" & i
  7.                c.Location = New System.Drawing.Point(gLeft, gTop)
  8.            If btnPicture <> "" And btnPicture <> Nothing Then
  9.                    gButton.Image = Image.FromFile(btnPicture)
  10.                End If
  11.                c.Visible = True
  12.                c.Visible = True
  13.                Exit For
  14.            End If
  15.         Next
  16.  
while i run the program, the image is diplaying in correct button if picture path exist and button that didn't have the picture path is displaying the text.

but the image is not fitting inside the Button. i can see only half of the image. i need a way to make the Image stretched or reduced to fit inside button.

is it possible??? if anyone have any idea how to do this, please help me. and if you can provide an example, then it will be great help for me.

Thanks in advance.
Oct 22 '08 #1
4 12408
joedeene
583 512MB
How about using the .BackgroundimageLayout Property and set it to ImageLayout.Stretch? Would that help?

joedeene
Oct 22 '08 #2
remya1000
115 100+
Thank you for your help.

Code i used to to display picture is

Expand|Select|Wrap|Line Numbers
  1. dim img as new bitmap(filename)
  2. dim img2 as new bitmap(img, mybutton.width, mybutton.height) 
  3. mybutton.Image = img2
  4.  
How can I remove the image from the button? is there a way to set the button image to "None"???

if anyone have any idea how to do this, please help me. and if you can provide an example, then it will be great help for me.

Thanks in advance.
Oct 23 '08 #3
Plater
7,872 Expert 4TB
mybutton.Image=null;
or for vb I suppose
mybutton.Image=nothing
Oct 23 '08 #4
remya1000
115 100+
that worked. thank you so much.

Expand|Select|Wrap|Line Numbers
  1. Button1.Image = Nothing
  2.  
Oct 23 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by gopal | last post: by
4 posts views Thread by truptidalia | last post: by
4 posts views Thread by =?Utf-8?B?YWxiZXJ0b3Nvcmlh?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.