Noah,
Give this a shot. Just set the size of the label to the size of the form in
the forms resize event. Used it for a similar problem. I think it's based
on some samples from Petzold's Programming MS Windows with C#
Enjoy,
-Robert
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2d;
namespace exp
{
public class ExpandoLabel : Label
{
public ExpandoLabel()
{
}
protected override void OnPaint( PaintEventArgs e )
{
GraphicsPath path;
RectangleF rectfBounds, rectfTemp;
if( this.Text == "" )
{
Console.WriteLine( "null string in paint" );
return;
};
path = new GraphicsPath();
path.AddString( "Ty", this.Font.FontFamily, (int)
this.Font.Style, 100,
new Point( 0, 0 ), new
StringFormat() );
rectfTemp = path.GetBounds();
path = new GraphicsPath();
path.AddString( this.Text, this.Font.FontFamily, (int)
this.Font.Style, 100,
new Point( 0, 0 ), new
StringFormat() );
rectfBounds = path.GetBounds();
rectfBounds.Height = rectfTemp.Height;
PointF[] aptfDest = { new PointF( 0, 0 ),
new PointF( this.Width, 0 ),
new PointF( 0,
this.Height ) };
e.Graphics.Transform = new Matrix( rectfBounds, aptfDest );
e.Graphics.SetClip( path );
e.Graphics.FillPath( new SolidBrush( this.ForeColor ), path );
}
}
}
"Noah Coad [.NET/C# MVP]" <no**@coad.net> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Thanks for the reply. I ment the actual size of the text within the
control. I suppose from your statement there isn't a "fill" for a font
size, that I'll have to play around with the sizes. That's the (sort of)
obvious way, I was looking for something quicker. Do you at least know if
there are classes (and if so, which ones) to determain the actual physical
size of some text?
Thanks,
-Noah Coad
MS MVP & MCP (.NET/C#)
"TJoker .NET" <no****@nonono.no> wrote in message
news:%2****************@tk2msftngp13.phx.gbl... If you are talking about a windows form user control, you can use the
Dock property of the control, setting it to Fill. But this will only resize
the control itself not the font of the text. If you want to find the most
appropriate font size you can fiddle with the GDI+ objects to measure
the string in different font sizes until you get a size that fits the best
in your control (the control's rectangle)
HTH
TJ
"Noah Coad [C# MCP]" <no**@coad.net> wrote in message
news:Oi**************@TK2MSFTNGP11.phx.gbl... I'm creating a program the must show the time (a clock) in a user
control and the text must fill the user control. How do I make text
dynamically resize to fill a label/panel/usercontrol? Thanks!!
-Noah Coad
Microsoft MVP & MCP (.NET/C#)