Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / January 2007

Tip: Looking for answers? Try searching our database.

Adjusting button height by font size

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bilz - 29 Jan 2007 18:33 GMT
All,

I came across some code that doesn't work very well.  It adjusts the
size of a button based on the font that we use.  The font can be
adjusted by the user.

using (Graphics g = this._btnClose.CreateGraphics())
{
   this._btnClose.Height = (int)(g.MeasureString(this._btnClose.Text,
this._btnClose.Font).Height * 1.25);
}

This is not enough, since the text is being cut off at the bottom (up
to 2 pixels).  To be honest, a factor of 1.25 seems rather arbitrary
to me.  I don't like this code for other reasons... one being that a
value of 25.99 will yield a value of 25.

I figure there is probably a better way.  Any suggestions?

Thanks,
Brian
Herfried K. Wagner [MVP] - 29 Jan 2007 19:00 GMT
"Bilz" <BrianGenisio@gmail.com> schrieb:
> I came across some code that doesn't work very well.  It adjusts the
> size of a button based on the font that we use.  The font can be
[quoted text clipped - 12 lines]
>
> I figure there is probably a better way.  Any suggestions?

Well, why not use a larger scaling factor?

Signature

M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>

Bilz - 29 Jan 2007 19:13 GMT
On Jan 29, 2:00 pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
h...@gmx.at> wrote:
>Well, why not use a larger scaling factor?
>
> --
>  M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
>  V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>

You're kidding, right?  Hard coding a "magic value" like that is sure
to fail again down the road again.
Bilz - 29 Jan 2007 19:02 GMT
> All,
>
[quoted text clipped - 16 lines]
> Thanks,
> Brian

Ok, I figured it out.  Instead of that funky math, I just set AutoSize
to true, and AutoSizeMode to GrowAndShrink.  This took care of it for
me.

Thanks,
B

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.