.net Button Control Image Size
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
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]
I limited the button's text length and the '.textimagerelation' keeps the image on the left of the text
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
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?
Do not load the image directly on the button, load in in an Image object first.
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:
Dim img As Image = My.Resources.[PUT A PICTURE HERE THATS IN YOUR RESOURCES]
Consult help to know what to pass in the extra parameters (...), I do not have the time to explain here.
b.Image = img.GetThumbnailImage([FORM AGAIN].Width, 50, ...)
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.
P.S. Also, I didn't have time to look up the getthumbnailimage method either!
Originally Posted by HeavyMetal69
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
By James Graham in forum .NET
Last Post: 10-23-2011, 02:47 PM
By LiveSys in forum VB Classic
Last Post: 04-15-2007, 06:30 PM
By Actipro Software Support in forum dotnet.announcements
Last Post: 03-16-2003, 07:40 PM
By AutomatedQA in forum dotnet.announcements
Last Post: 11-19-2001, 05:08 PM
By Developer Express in forum dotnet.announcements
Last Post: 10-06-2001, 02:43 PM
Tags for this Thread
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