473,656 Members | 2,921 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Ceili ng(g.MeasureStr ing(this.Text,
this.Font, this.Width - this.Padding.Le ft,
StringFormat.Ge nericDefault).H eight);

Then override the onPaint and do this...
e.Graphics.Draw String(this.Tex t, this.Font, new
SolidBrush(this .ForeColor), new
Rectangle(this. Padding.Left,th is.Padding.Top, this.Width -
this.Padding.Le ft,this.Height) , StringFormat.Ge nericDefault);

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.Me asureText(g, this.Text,
this.Font, this.Size, TextFormatFlags .Bottom).Height ;

and draw like this...

TextRenderer.Dr awText(e.Graphi cs, this.Text, this.Font,
this.ClientRect angle, this.ForeColor, this.BackColor,
TextFormatFlags .Default);
The label doesn't resize, and even if I use the resize code from the
Graphics.Measur eString, the TextRender.Draw Text doesn't work.

Please help!

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

"Nathan Laff" <re******@hotma il.comwrote in message
news:E9******** *************** ***********@mic rosoft.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.Ceili ng(g.MeasureStr ing(this.Text,
this.Font, this.Width - this.Padding.Le ft,
StringFormat.Ge nericDefault).H eight);

Then override the onPaint and do this...
e.Graphics.Draw String(this.Tex t, this.Font, new
SolidBrush(this .ForeColor), new
Rectangle(this. Padding.Left,th is.Padding.Top, this.Width -
this.Padding.Le ft,this.Height) , StringFormat.Ge nericDefault);

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.Me asureText(g, this.Text,
this.Font, this.Size, TextFormatFlags .Bottom).Height ;

and draw like this...

TextRenderer.Dr awText(e.Graphi cs, this.Text, this.Font,
this.ClientRect angle, this.ForeColor, this.BackColor,
TextFormatFlags .Default);
The label doesn't resize, and even if I use the resize code from the
Graphics.Measur eString, the TextRender.Draw Text 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
2372
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 graphics object of the form/pictureBox. Should It be better if make a graphics object from my pictureBox in load event handler of the form and store it as member variable of the form , make
14
3094
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 to do this? E.g. I want to be able to graph a function. At this point I'm not up to a level in C++ where I want to start learning Visual C++ so I don't want to go that route. Thanks
5
27148
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 e.Graphics.DrawString(Line1.Text, FontLine1, TheBrush, Thelocation1, 390 + yPos, AStringFormat) e.Graphics.DrawString(Line2.Text, FontLine2, TheBrush, Thelocation2, TheHeight1 + (390 + yPos))
2
2801
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 the rectangle on LargeIcon mode... I thought I'd finally discovered the solution with TextRenderer but this still doesn't give the correct results. Here's the code I'm trying to use (item is a ListViewItem)
6
3241
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 (much like the current model), but my PrintDocument would have a Pages collection such that each time you need to have an additional page, you would just add another page to the collection and then use the page object for the actual drawing etc. ...
12
3584
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 utilities that allows you to view them with live rotation in a web browser. Also, it includes a introductory tutorial to POV-Ray.
6
10676
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# application and add a Paint event handler): public partial class Form1 : Form { public Form1() { InitializeComponent();
6
10539
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 short string width. What is it I am doing wrong? Here the code I am using: private void MinimizeDgvColumns(DataGridView dgv)
4
4871
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 characters "T", "E", "S", and "T" and then added the resulting values together. The problem is that the two values don't seem to match unless the Graphics.PageUnit is set to Inch. I don't understand why it doesn't work with the default setting of...
0
8382
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8297
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
7311
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5629
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1930
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1600
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.