Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 22nd, 2008, 02:13 PM
Authorized User
 
Join Date: Sep 2007
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default Image stretch or reduced to fit inside button

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.
 
Old October 22nd, 2008, 02:16 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Take a look at Graphics.MeasureString. It allows you to measure the size of a string, given a specific canvas, font and so on.

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
 
Old October 23rd, 2008, 11:36 AM
Authorized User
 
Join Date: Sep 2007
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default


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.
 
Old October 23rd, 2008, 12:52 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Have you tried setting it to null?

Did MeasureString work for you?

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
 
Old October 23rd, 2008, 03:11 PM
Authorized User
 
Join Date: Sep 2007
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default

that worked. thank you so much for your help.
 
Old October 23rd, 2008, 03:15 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

>> Did MeasureString work for you?

Did it?

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding an un-named button inside a webpage gillevk C# 1 July 23rd, 2007 11:29 AM
Make a image button as default submit button toshi ASP.NET 1.0 and 1.1 Basics 1 June 1st, 2006 05:25 AM
Adding code to a button inside a custom Control. Roinka ASP.NET 2.0 Basics 5 April 23rd, 2006 01:03 PM
Redirect inside a Server Control Button Andrew_S ASP.NET 2.0 Basics 1 April 19th, 2006 01:43 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.