473,396 Members | 2,108 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,396 software developers and data experts.

Graphics to TextRenderer

I have a custom label, that as the width changes, the height will change to
fit all the text in the label...

I use to do this like this...

int newHeight = (int)Math.Ceiling(g.MeasureString(this.Text,
this.Font, this.Width - this.Padding.Left,
StringFormat.GenericDefault).Height);

Then override the onPaint and do this...
e.Graphics.DrawString(this.Text, this.Font, new
SolidBrush(this.ForeColor), new
Rectangle(this.Padding.Left,this.Padding.Top,this. Width -
this.Padding.Left,this.Height), StringFormat.GenericDefault);

Works great.

Now I'm trying to move to TextRenderer and can't seem to get it to do either
of these things.

I'm trying to measure like this...

int newHeight = TextRenderer.MeasureText(g, this.Text,
this.Font, this.Size, TextFormatFlags.Bottom).Height;

and draw like this...

TextRenderer.DrawText(e.Graphics, this.Text, this.Font,
this.ClientRectangle, this.ForeColor, this.BackColor,
TextFormatFlags.Default);
The label doesn't resize, and even if I use the resize code from the
Graphics.MeasureString, the TextRender.DrawText doesn't work.

Please help!

May 10 '07 #1
1 8048
Nevermind. WordBreak was the magic style

"Nathan Laff" <re******@hotmail.comwrote in message
news:E9**********************************@microsof t.com...
>I have a custom label, that as the width changes, the height will change to
fit all the text in the label...

I use to do this like this...

int newHeight = (int)Math.Ceiling(g.MeasureString(this.Text,
this.Font, this.Width - this.Padding.Left,
StringFormat.GenericDefault).Height);

Then override the onPaint and do this...
e.Graphics.DrawString(this.Text, this.Font, new
SolidBrush(this.ForeColor), new
Rectangle(this.Padding.Left,this.Padding.Top,this. Width -
this.Padding.Left,this.Height), StringFormat.GenericDefault);

Works great.

Now I'm trying to move to TextRenderer and can't seem to get it to do
either of these things.

I'm trying to measure like this...

int newHeight = TextRenderer.MeasureText(g, this.Text,
this.Font, this.Size, TextFormatFlags.Bottom).Height;

and draw like this...

TextRenderer.DrawText(e.Graphics, this.Text, this.Font,
this.ClientRectangle, this.ForeColor, this.BackColor,
TextFormatFlags.Default);
The label doesn't resize, and even if I use the resize code from the
Graphics.MeasureString, the TextRender.DrawText doesn't work.

Please help!
May 11 '07 #2

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

Similar topics

12
by: Sanjay | last post by:
hi, We are currently porting our project from VB6 to VB .NET. Earlier we used to make scale transformations on objects like pictureBox , forms etc.Now Such transformations are made on the...
14
by: Pmb | last post by:
At the moment I'm using Borland's C++ (http://www.borland.com/products/downloads/download_cbuilder.html#) I want to be able to take an array of points and plot them on the screen. Is there a way...
5
by: Charles A. Lackman | last post by:
Hello, I have created a complete PrintDocument and need to create an image from it. How is this done? e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality...
2
by: Xafier | last post by:
Hi, I'm creating a control that overrides ListView and so I'm working on redrawing everything myself with some changes here and there... But I'm having a problem with drawing the text inside...
6
by: Chris Dunaway | last post by:
The method for printing documents in .Net can be confusing, especially for newer users. I would like to create a way to simplify this process. My idea would be implemented using a PrintDocument...
12
by: Xah Lee | last post by:
Of Interest: Introduction to 3D Graphics Programing http://xahlee.org/3d/index.html Currently, this introduction introduces you to the graphics format of Mathematica, and two Java Applet...
6
vekipeki
by: vekipeki | last post by:
I am having a problem with basic drawing of unicode characters in Windows 2000 and XP. I have written a simplest possible C# WinForms program to test it (just create a new Windows Forms C#...
6
by: Rainer Queck | last post by:
Hello NG, I am trying to adjust the column width of a DataGridView to the Text in its column header. To do this I am using the Graphics.MeasureString method. Unfortunatly I alway get a too...
4
nukefusion
by: nukefusion | last post by:
I'm having trouble using MeasureCharacterRanges. If I use it to get the width of the string "TEST" I would expect to get the same width as I would if I used it to get the individual widths of the...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.