compactframework >> adjust font to label height?

by VGltIFJhbWw » Wed, 20 Jul 2005 05:44:04 GMT

ive read the posts about adjusting height to font, but i want to adjust font
to height. is there an easy solution to this?

thanks in advance,
tim

compactframework >> adjust font to label height?

by Norbert » Wed, 20 Jul 2005 15:49:07 GMT


The only way I can think of
would be creating your own Label Class
and overriding the OnPaint Method
There you can get the Height of your Label
and based on it select a coresponding FontSize.


But I dont know if you can derive from "Label"
because for example deriving from Button is Pointless
because this is only a wrapper for an OS-Button

compactframework >> adjust font to label height?

by VGltIFJhbWw » Wed, 20 Jul 2005 20:36:03 GMT

im currently resizing my controls in the resize event; im trying to figure
out if theres an easy way to get the font that will fit the height of the
label. the only soln i could think of is creating a loop and increasing the
font size and checking if the font fits the height of the label but i was
hoping theres an easier soln...

compactframework >> adjust font to label height?

by Norbert » Thu, 21 Jul 2005 19:51:30 GMT

I hardly believ you have another solution

The Height Property isn't supported in the Compact Framework

If it takes to much time, you can try to create an fixed multiplier for
this calculation
(simple go through the loop, generate all Heights in pixel and try to
figure out an
mutliplier)

If there is no constant multiplier (if its a function of higher order)
you can try to create
an array of Font heights (integer) where for example the 10 elemet
contains the font height which result in 10 pixel height and so on. But
I think this is a little bit overdesigned...

regards Norbert

compactframework >> adjust font to label height?

by VGltIFJhbWw » Thu, 21 Jul 2005 21:36:11 GMT

im working in the v1.1 cf and the label height property works fine.

based on the responses, i guess looping through and increasing the font size
is the only soln...

compactframework >> adjust font to label height?

by Sergey Bogdanov » Sat, 23 Jul 2005 15:09:33 GMT

It could be done a bit faster - instead of using linear searching you
may try to use binary algorithm. See this example for searching optimal
string length for bounded width:
http://www.sergeybogdanov.com/samples/OptimalStrLength.zip

In your case instead of string length you should use font size.

Similar Threads

1. Auto adjust label height

2. Adjusting button height by font size

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

3. Does Font.Height or Font.GetHeight() return correct font height? - CSharp/C#

4. adjust the row height for some rows

I am creating DataGrid Dynamically on the fly and binding an empty one 
column datatable through a DataView object
I would like to dynamically adjust the row height for some rows of the 
datagrid. Everything is done in the Page_Load event as follows

                dgDynamic = 
System.Activator.CreateInstance(GetType(DataGrid))
                dgDynamic.AutoGenerateColumns = False
                dgDynamic.CssClass = "dgcss"
                dgDynamic.DataSource = CreateDataSource()
                dgDynamic.DataBind()

                Then when I try to acces the table control as follows I

                'Dim Tbl As Table = dgDynamic.Controls(0)"
                I get out of index error, when checking in a debug session 
the dgDynamic.controls.coun = 0

                Any ideas  or example on how to manipulate the cells ?

                Thanks 


5. Automatically adjust TextBox's height - ASP.NET Web Controls

6. Can't adjust table height

My form contains only a filled in table.

I'd like to make the table height be a fixed pixel value.

I tried putting height on the <asp:Table
and on the <asp:TableRow
and on the <asp:TableCell

None of the above seen to make any difference.
In all cases the table adjusts itself to the cell contents.

My first choice would be to set rows with various heights.

Failing that, I'd like to set the table height and let the row heights all 
be equal.

Can you tell what I'm doing wrong?


Thanks in advance




7. Getting an asp.net TextBox to fill a screen and adjust height dynamically - Asp.Net

8. Getting an asp.net TextBox to fill a screen and adjust height

xhtml has no replacement (it just depicated, not removed), but its a valid 
event for html 4.0/ 5.0/ xhtml2 (undepicated if htmlelement). 


-- bruce (sqlwork.com)


"Terry" wrote:

> Thanks Bruce!  That that worked exactly as I had hoped.
> 
> I did find that the "onresize" event in the body element is not valid
> for XHTML Transitional markup.  I took out the DOCTYPE reference to
> test your code, and it worked.  I'll probably have to find a work-
> around for the onresize event if I want my web page to enforce XHTML
> Transitional.
> 
> Thanks again.
>