473,387 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Dynamically Resize Text

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#)
Nov 13 '05 #1
2 15154
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#)


Nov 13 '05 #2

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#)



Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: michael | last post by:
I have an html text string within a div, eg.: <div id="example">Text text text</div> I know its easy to change styles by using getElementById - for example: ...
3
by: Guadala Harry | last post by:
Here's the functionality I'm after: I need for a page to display a photo. When users click on other links within the page, the photo changes. I'd like to swap out the photo without doing a...
4
by: Stu | last post by:
Hi, I am writing a content management system that has to have W3C compliant output. The pages are template driven and there are special strings within the template to be used as placeholders for...
6
by: jawolter | last post by:
I have a list of links that are sometimes too long to display on a given screen. I want to trim the ends of them if they are too long, and show dot dot dot. If the browser is widened, though, and...
2
by: Magenta | last post by:
What I'd like to do display a form that consists of subforms, and allow a user to resize the sections of a form at will. For example, if a form has three subforms, each placed vertically and...
1
by: garyusenet | last post by:
Hi, I will outline what i'm trying to do here, and would really like to here your suggestions of how I can do it please. I have some code which finds the open internet explorer windows. I...
1
by: Teelions | last post by:
I know that this can be done for iframes but am wondering if it can be also done for layers. I have 2 pages: an asp content page that has a html (toc.html) include placed within it. The...
1
by: pskvenkat | last post by:
Hi this is venkat, I am Using Asp.net (C#) . Can you give me the details for how to store the dynamically created text box value into sql server database. pls give me a code if any?
1
by: adarshyam | last post by:
can anybody tel me how to clear values from dynamically created text boxes?? using a clear button.. this is the code used to create dynamic text boxes.. if i press clear button then it must clear all...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.