DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2009
    Posts
    4

    Thumbs up .net Button Control Image Size

    Info:
    I need to know how to make sure the image on the left is always the same size

    I want to make sure the image does not overlap the text on the button

    I do not want to drop the 'button' control because I am using text and image and have my entire application integrated with this concept

    I cannot resize my buttons, they should all be the same size
    -----------------------------------------------------------------

    Problems:
    Image size changes depending on the image
    I am allowing the user to select their own image so I cannot use any other option but to resize the original format to what will fit on the button.


    Ok, here is my code:
    dim b as button
    For Each i In [FORM GOES HERE].lstInfo.Items
    b = New Button
    'b.TextAlign = ContentAlignment.MiddleCenter
    b.TextImageRelation = TextImageRelation.ImageBeforeText
    b.Text = i.Text
    b.Name = "btn" & b.Text
    b.ImageAlign = ContentAlignment.MiddleLeft
    b.Image = My.Resources.[PUT A PICTURE HERE THATS IN YOUR RESOURCES]
    [FORM GOES HERE].Controls.Add(b)
    'MsgBox("Adding: " & b.Name)
    b.Size = New Size([FORM AGAIN].Width, 50)
    AddHandler b.Click, AddressOf [MY HANDLE]
    Next



    P.S:
    I limited the button's text length and the '.textimagerelation' keeps the image on the left of the text

    Thank you

  2. #2
    Join Date
    Sep 2009
    Posts
    4

    Smile Also:

    Part of the loop I cut out was the spacing of the buttons so if you have to test this to answer, make sure the next button's .top property is increased

    Thanks all!

  3. #3
    Join Date
    Sep 2009
    Posts
    4

    Cool Idea

    Maybe I need to adjust the image size at the resource level, I have not made an imagelist or anything like that, anytime I need an image, I import it with the built-in Visual Studio option in the property list for the control

    Maybe I can access this and adjust it there?

  4. #4
    Join Date
    Feb 2004
    Location
    Longueuil, Québec
    Posts
    577
    Do not load the image directly on the button, load in in an Image object first.

    Code:
    Dim img As Image = My.Resources.[PUT A PICTURE HERE THATS IN YOUR RESOURCES]
    The Image object has a method GetThumbnailImage that returns a version of the image resized as desired. This is usually used to display a series of images as does Windows Explorer, but it should work in you situation:

    Code:
    b.Image = img.GetThumbnailImage([FORM AGAIN].Width, 50, ...)
    Consult help to know what to pass in the extra parameters (...), I do not have the time to explain here.
    Jacques Bourgeois
    JBFI
    http://www3.sympatico.ca/jbfi/homeus.htm

  5. #5
    Join Date
    Sep 2009
    Posts
    4

    Resolved

    Thank you for your suggestion, I experimented for a while and ended up using the following

    Dim img As New Bitmap(PATH, WIDTH, HEIGHT)
    .Image = img

    I didn't think about not loading the image directly into the button until you said that.

    Thank you


    P.S. Also, I didn't have time to look up the getthumbnailimage method either!

  6. #6
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,649
    Quote Originally Posted by HeavyMetal69 View Post
    P.S. Also, I didn't have time to look up the getthumbnailimage method either!
    GetThumbNailImage
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

Similar Threads

  1. Replies: 4
    Last Post: 10-23-2011, 02:47 PM
  2. How To save image in MDB from image control.
    By LiveSys in forum VB Classic
    Replies: 1
    Last Post: 04-15-2007, 06:30 PM
  3. Actipro Wizard 2.0 Released (Windows Forms Control)
    By Actipro Software Support in forum dotnet.announcements
    Replies: 0
    Last Post: 03-16-2003, 07:40 PM
  4. Replies: 0
    Last Post: 11-19-2001, 05:08 PM
  5. ANN: The XtraGrid Suite & XtraEditors Library - 100% Native .NET Components
    By Developer Express in forum dotnet.announcements
    Replies: 0
    Last Post: 10-06-2001, 02:43 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links