PC Review


Reply
Thread Tools Rate Thread

Word wrapping on DrawString method

 
 
Marcos Cruz Arjona
Guest
Posts: n/a
 
      22nd May 2004
Hi,

In order to draw a formatted text inside a rectangle on a custom
control, I use Graphics.DrawString(string, Font, Brush, RectangleF) method.
However, when the text is too large for the specified rectangle, the method
word wraps the text, instead of just clipping it on a single line.
Therefore, do I have to use DrawText unmanaged function or is there a
workaround?


Best regards,

M a r c o s


 
Reply With Quote
 
 
 
 
Alex Feinman [MVP]
Guest
Posts: n/a
 
      22nd May 2004
Try setting the RectangleF parameter to be the height of the single line of
text. To do this, use MeasureString with a string short enough not to wrap

--
Alex Feinman
---
Visit http://www.opennetcf.org
"Marcos Cruz Arjona" <(E-Mail Removed)> wrote in message
news:e%(E-Mail Removed)...
> Hi,
>
> In order to draw a formatted text inside a rectangle on a custom
> control, I use Graphics.DrawString(string, Font, Brush, RectangleF)

method.
> However, when the text is too large for the specified rectangle, the

method
> word wraps the text, instead of just clipping it on a single line.
> Therefore, do I have to use DrawText unmanaged function or is there a
> workaround?
>
>
> Best regards,
>
> M a r c o s
>
>



 
Reply With Quote
 
 
 
 
Marcos Cruz Arjona
Guest
Posts: n/a
 
      22nd May 2004
Alex,

I had already tried this and it doesn't works. DrawString always cuts
words (separated by spaces) that doesn't fit in the specified rectangle
width, in spite of rectangle height.

Thanks,

M a r c o s

"Alex Feinman [MVP]" <(E-Mail Removed)> escribió en el mensaje
news:%(E-Mail Removed)...
> Try setting the RectangleF parameter to be the height of the single line

of
> text. To do this, use MeasureString with a string short enough not to wrap
>
> --
> Alex Feinman
> ---
> Visit http://www.opennetcf.org
> "Marcos Cruz Arjona" <(E-Mail Removed)> wrote in message
> news:e%(E-Mail Removed)...
> > Hi,
> >
> > In order to draw a formatted text inside a rectangle on a custom
> > control, I use Graphics.DrawString(string, Font, Brush, RectangleF)

> method.
> > However, when the text is too large for the specified rectangle, the

> method
> > word wraps the text, instead of just clipping it on a single line.
> > Therefore, do I have to use DrawText unmanaged function or is there a
> > workaround?
> >
> >
> > Best regards,
> >
> > M a r c o s
> >
> >

>
>



 
Reply With Quote
 
Tim Wilson
Guest
Posts: n/a
 
      22nd May 2004
One way to do this is to define the clipping region for the Graphics object
and then use the DrawString overload that takes X and Y coordinates [public
void DrawString(string, Font, Brush, float, float)].

<Basic Idea>
e.Graphics.Clip = new Region(new Rectangle(0, 0, 50, 20));
e.Graphics.DrawString("This is a pretty long string of text!", this.Font,
new SolidBrush(Color.Black), 0, 0);
e.Graphics.ResetClip();
</Basic Idea>

--
Tim Wilson
..Net Compact Framework MVP
{cf147fdf-893d-4a88-b258-22f68a3dbc6a}
"Marcos Cruz Arjona" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Alex,
>
> I had already tried this and it doesn't works. DrawString always cuts
> words (separated by spaces) that doesn't fit in the specified rectangle
> width, in spite of rectangle height.
>
> Thanks,
>
> M a r c o s
>
> "Alex Feinman [MVP]" <(E-Mail Removed)> escribió en el mensaje
> news:%(E-Mail Removed)...
> > Try setting the RectangleF parameter to be the height of the single line

> of
> > text. To do this, use MeasureString with a string short enough not to

wrap
> >
> > --
> > Alex Feinman
> > ---
> > Visit http://www.opennetcf.org
> > "Marcos Cruz Arjona" <(E-Mail Removed)> wrote in message
> > news:e%(E-Mail Removed)...
> > > Hi,
> > >
> > > In order to draw a formatted text inside a rectangle on a custom
> > > control, I use Graphics.DrawString(string, Font, Brush, RectangleF)

> > method.
> > > However, when the text is too large for the specified rectangle, the

> > method
> > > word wraps the text, instead of just clipping it on a single line.
> > > Therefore, do I have to use DrawText unmanaged function or is there a
> > > workaround?
> > >
> > >
> > > Best regards,
> > >
> > > M a r c o s
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Marcos Cruz Arjona
Guest
Posts: n/a
 
      22nd May 2004
Tim,

I'll try this!

Thanks,

M a r c o s

"Tim Wilson" <TIM(UNDERSCORE)WILSON(AT)ROGERS(PERIOD)COM> escribió en el
mensaje news:(E-Mail Removed)...
> One way to do this is to define the clipping region for the Graphics

object
> and then use the DrawString overload that takes X and Y coordinates

[public
> void DrawString(string, Font, Brush, float, float)].
>
> <Basic Idea>
> e.Graphics.Clip = new Region(new Rectangle(0, 0, 50, 20));
> e.Graphics.DrawString("This is a pretty long string of text!", this.Font,
> new SolidBrush(Color.Black), 0, 0);
> e.Graphics.ResetClip();
> </Basic Idea>
>
> --
> Tim Wilson
> .Net Compact Framework MVP
> {cf147fdf-893d-4a88-b258-22f68a3dbc6a}
> "Marcos Cruz Arjona" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> > Alex,
> >
> > I had already tried this and it doesn't works. DrawString always cuts
> > words (separated by spaces) that doesn't fit in the specified rectangle
> > width, in spite of rectangle height.
> >
> > Thanks,
> >
> > M a r c o s
> >
> > "Alex Feinman [MVP]" <(E-Mail Removed)> escribió en el

mensaje
> > news:%(E-Mail Removed)...
> > > Try setting the RectangleF parameter to be the height of the single

line
> > of
> > > text. To do this, use MeasureString with a string short enough not to

> wrap
> > >
> > > --
> > > Alex Feinman
> > > ---
> > > Visit http://www.opennetcf.org
> > > "Marcos Cruz Arjona" <(E-Mail Removed)> wrote in message
> > > news:e%(E-Mail Removed)...
> > > > Hi,
> > > >
> > > > In order to draw a formatted text inside a rectangle on a custom
> > > > control, I use Graphics.DrawString(string, Font, Brush, RectangleF)
> > > method.
> > > > However, when the text is too large for the specified rectangle, the
> > > method
> > > > word wraps the text, instead of just clipping it on a single line.
> > > > Therefore, do I have to use DrawText unmanaged function or is there

a
> > > > workaround?
> > > >
> > > >
> > > > Best regards,
> > > >
> > > > M a r c o s
> > > >
> > > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Word wrapping in Graphics.DrawString breaks words at umlauts Franz Häring Microsoft Dot NET Framework 0 23rd Mar 2005 12:34 PM
Drawstring method =?Utf-8?B?Qi4gQ2hlcm5pY2s=?= Microsoft Dot NET Framework Forms 1 24th Oct 2004 03:38 PM
drawstring with line wrapping? Danie Microsoft VB .NET 4 8th Oct 2003 11:20 AM
drawstring method doesn't work with all printers Robert in Phoenix Microsoft C# .NET 3 24th Sep 2003 02:54 PM
DrawString Method Mark Keats Microsoft C# .NET 1 1st Aug 2003 06:56 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:07 AM.