Roman
Mon Nov 27 09:40:43 CST 2006
Measuring the string will help you to find out whether the string fits
or not, but if you want to get the max string that fits the width of
your form u have a problem.
There ar 2 solutions in my mind:
1) use a font with a fixed character width, measure the width of one
char and display
x chars of your string where FormWidth > charWidth * x
2) do something like a binary search:
a) while the string is too long retry with the first half of your
string after that
b) while the string is not too long add the half of the remaining
string
not very nice but it will run
Bob Powell [MVP] schrieb:
> You can use Graphics.MeasureString to get a size. You'll need to maybe use a
> fudge factor to account for the buttons and the icons.
>
> --
> Bob Powell [MVP]
> Visual C#, System.Drawing
>
> Ramuseco Limited .NET consulting
>
http://www.ramuseco.com
>
> Find great Windows Forms articles in Windows Forms Tips and Tricks
>
http://www.bobpowell.net/tipstricks.htm
>
> Answer those GDI+ questions with the GDI+ FAQ
>
http://www.bobpowell.net/faqmain.htm
>
> All new articles provide code in C# and VB.NET.
> Subscribe to the RSS feeds provided and never miss a new article.
>
>
>
> "Eve" <Eve@discussions.microsoft.com> wrote in message
> news:C755284D-CCC9-4559-8D2E-BE86DB82A896@microsoft.com...
> > I'm assigning a description to my form title, such as:
> > strDesc = "This is a test if the description will fit in"
> > frmTest.Text = "(" & strDesc & ")"
> >
> > If strDesc doesn't fit in the title, I don't see the closing paranthesis:
> > ("This is a test if the description will fi..."
> >
> > I would like to be able to determine if strDesc will fit into the space
> > provided, and if it won't fit, I would like display only as much as would
> > fit:
> > ("This is a test if the description will f...)"
> >
> > How can I do this? Thank you!