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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • remya1000
    New Member
    • Apr 2007
    • 115

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

    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

    Code:
           For Each c As Control In Controls
                If c.Name = "ItemBtn-" & x Then
                   c.Text = ButtonText
                   c.ForeColor = System.Drawing.ColorTranslator.FromOle(btnFontColor)
                   c.BackColor = System.Drawing.ColorTranslator.FromOle(btnBackColor)
                   c.Tag = "ItemPageBtn-" & i
                   c.Location = New System.Drawing.Point(gLeft, gTop)
    	       If btnPicture <> "" And btnPicture <> Nothing Then
                       gButton.Image = Image.FromFile(btnPicture)
                   End If
                   c.Visible = True
                   c.Visible = True
                   Exit For
               End If
            Next
    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.
  • joedeene
    Contributor
    • Jul 2008
    • 579

    #2
    How about using the .Backgroundimag eLayout Property and set it to ImageLayout.Str etch? Would that help?

    joedeene

    Comment

    • remya1000
      New Member
      • Apr 2007
      • 115

      #3
      Thank you for your help.

      Code i used to to display picture is

      Code:
      dim img as new bitmap(filename)
      dim img2 as new bitmap(img, mybutton.width, mybutton.height) 
      mybutton.Image = img2
      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.

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        mybutton.Image= null;
        or for vb I suppose
        mybutton.Image= nothing

        Comment

        • remya1000
          New Member
          • Apr 2007
          • 115

          #5
          that worked. thank you so much.

          Code:
          Button1.Image = Nothing

          Comment

          Working...