Re: Font size based on the client rectangle of the control.
- From: kiranreddyd@xxxxxxxxx
- Date: 26 Sep 2006 05:53:40 -0700
Thanks Bob! This is excatly what I want.
Regards
Kiran
Bob Powell [MVP] wrote:
The only way to change the font width independently of the height is to draw
the text using a matrix that distorts the glyphs.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.SetStyle(ControlStyles.ResizeRedraw, true);
}
Font fn = new Font("Arial", 72);
String s = "Hello World";
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
SizeF sf = e.Graphics.MeasureString(s, fn);
Matrix mx = new Matrix(1.0f / sf.Width * this.ClientRectangle.Width, 0, 0,
1.0f / sf.Height * this.ClientRectangle.Height, 0, 0);
e.Graphics.Transform = mx;
e.Graphics.DrawString(s, fn, Brushes.Black, new PointF(0, 0));
}
}
--
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.
<kiranreddyd@xxxxxxxxx> wrote in message
news:1158644036.131479.100900@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi,
I am looking at functionality something like WordArt in MS Word. If
you increase the height the text height is increased without increasing
Width. The same happens for width too or both can be increased. How can
this be achieved? Thanks.
Regards
Kiran
Bob Powell [MVP] wrote:
There is no easy answer for this. The font size needs to be tried and
readjusted, possibly using a binary chop algorithm, to obtain the correct
size.
The trouble is that changing the font size also changes the number of
characters on a line which changes the number of lines in a given
rectangle
which.... you get the picture.
--
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.
<kiranreddyd@xxxxxxxxx> wrote in message
news:1158583443.933730.235040@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi,
I have a control that render text. This is done in OnPaint()
override by drawing the text. When the control is resized, the text
inside it should also be resized according to the size of the control.
Either height of the text or width of the text or both need to be
resized. So I need to determine the font size based on the current
client rectangle. How do I do this? Is there any other way of resizing
the text?
I am using .Net 2.0. Your help is highly appreciated.
Thanks in Advance.
Regards
Kiran
.
- References:
- Font size based on the client rectangle of the control.
- From: kiranreddyd
- Re: Font size based on the client rectangle of the control.
- From: Bob Powell [MVP]
- Re: Font size based on the client rectangle of the control.
- From: kiranreddyd
- Re: Font size based on the client rectangle of the control.
- From: Bob Powell [MVP]
- Font size based on the client rectangle of the control.
- Prev by Date: Improving Paint performance while Scrolling
- Next by Date: Re: MDI Child jiggles like a bowl full of jelly.
- Previous by thread: Re: Font size based on the client rectangle of the control.
- Next by thread: custom gridviw column
- Index(es):
Relevant Pages
|