kiranreddyd
Tue Sep 26 07:53:40 CDT 2006
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@gmail.com> wrote in message
> news:1158644036.131479.100900@m73g2000cwd.googlegroups.com...
> > 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@gmail.com> wrote in message
> >> news:1158583443.933730.235040@k70g2000cwa.googlegroups.com...
> >> > 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
> >> >
> >