473,246 Members | 1,812 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,246 software developers and data experts.

DrawString, multiline string but full width

Hello.
It seems like the default behavior of DrawString is trying to keep the
whole word if possible. I'd like the string to be drawn in multilines,
but filling the entire line width.
For example I'm using a fixed-width font, and the width of the layout
rectangle is that of 12 characters, the result I want is,
This is a sa
mple text.
not,
This is a
sample text.

I set the StringFormatFlags.Wrap = false, but it disabled multiline
drawing that wasn't what I wanted.

Is what I'm trying to do achievable with any formatting options or do
I have to draw each character manually with my own calculation?
Jun 27 '08 #1
4 6120
On Fri, 25 Apr 2008 21:51:04 -0700, Sin Jeong-hun <ty*******@gmail.com>
wrote:
It seems like the default behavior of DrawString is trying to keep the
whole word if possible. I'd like the string to be drawn in multilines,
but filling the entire line width.
[...]
Is what I'm trying to do achievable with any formatting options or do
I have to draw each character manually with my own calculation?
Off the top of my head, I think maybe you want to set the
StringFormat.Trimming property to Character.

If I'm mistaken about that, you may be able to use the TextRenderer class
instead to do your drawing, using the TextFormatFlags.WordBreak flag (or
rather, making sure that flag is _not_ set) to have the text wrapped on
whatever character reaches the very end of the line.

Sorry I'm being so vague...I don't have something right in front of me
that would let me test the code to make sure my recollection is right.

Pete
Jun 27 '08 #2
On Apr 26, 3:29*pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
On Fri, 25 Apr 2008 21:51:04 -0700, Sin Jeong-hun <typing...@gmail.com*
wrote:
It seems like the default behavior of DrawString is trying to keep the
whole word if possible. I'd like the string to be drawn in multilines,
but filling the entire line width.
[...]
Is what I'm trying to do achievable with any formatting options or do
I have to draw each character manually with my own calculation?

Off the top of my head, I think maybe you want to set the *
StringFormat.Trimming property to Character.

If I'm mistaken about that, you may be able to use the TextRenderer class *
instead to do your drawing, using the TextFormatFlags.WordBreak flag (or *
rather, making sure that flag is _not_ set) to have the text wrapped on *
whatever character reaches the very end of the line.

Sorry I'm being so vague...I don't have something right in front of me *
that would let me test the code to make sure my recollection is right.

Pete
Thank you for your reply. But, DrawString() with Trimming property set
to Character didn't work. It was the same as when I didn't even set
the Trimming property. Secondly, TextRender.DrawText draws multiline
text if and only if the TextFormatFlag has WordBreak. Setting
WorkBreak gave the same result as when I used DrawString().
Jun 27 '08 #3
On Apr 26, 5:27*pm, Sin Jeong-hun <typing...@gmail.comwrote:
On Apr 26, 3:29*pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
On Fri, 25 Apr 2008 21:51:04 -0700, Sin Jeong-hun <typing...@gmail.com*
wrote:
It seems like the default behavior of DrawString is trying to keep the
whole word if possible. I'd like the string to be drawn in multilines,
but filling the entire line width.
[...]
Is what I'm trying to do achievable with any formatting options or do
I have to draw each character manually with my own calculation?
Off the top of my head, I think maybe you want to set the *
StringFormat.Trimming property to Character.
If I'm mistaken about that, you may be able to use the TextRenderer class *
instead to do your drawing, using the TextFormatFlags.WordBreak flag (or*
rather, making sure that flag is _not_ set) to have the text wrapped on *
whatever character reaches the very end of the line.
Sorry I'm being so vague...I don't have something right in front of me *
that would let me test the code to make sure my recollection is right.
Pete

Thank you for your reply. But, DrawString() with Trimming property set
to Character didn't work. It was the same as when I didn't even set
the Trimming property. Secondly, TextRender.DrawText draws multiline
text if and only if the TextFormatFlag has WordBreak. Setting
WorkBreak gave the same result as when I used DrawString().
Please just let me know if what I'm trying to do cannot be achieved
with some flags. Then I can start writing manual line breaking codes.
Thank you.

Jun 27 '08 #4
On Sat, 26 Apr 2008 18:29:12 -0700, Sin Jeong-hun <ty*******@gmail.com>
wrote:
Please just let me know if what I'm trying to do cannot be achieved
with some flags. Then I can start writing manual line breaking codes.
For what it's worth, it's very difficult with many esoteric operations for
a person to say for sure that you can't do it easily in .NET. .NET is
incredibly broad in many areas. If a person knows for sure that there
_is_ a way to do it, that's one thing. But to prove that you can't is
much harder.

In other words, you may not find anyone who is confident that their
knowledge is encyclopedic enough about .NET to state for sure that there's
no option that will break a line within a word rather than between words.
And this may be true even if it turns out that you actually can't.

I'm actually surprised that neither of the options I mentioned address the
issue. Just as I can't say for sure that what you want isn't in .NET, I
also can't say for sure that you have successfully applied the options I
mentioned in a way that would perform as you want. It's possible that
they only work in that specific way when used in combination with other
aspects of text formatting and that you haven't tried that particular
combination yet.

But, the fact is that Graphics.DrawString() and TextRenderer.DrawText()
are the two primary ways to draw text in .NET. If you're sure you've
explored all of the viable combinations of settings and overloads for each
of those methods and none do what you want, I suppose you might as well
start working on a more explicit implementation instead.

Pete
Jun 27 '08 #5

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

Similar topics

2
by: Mark Keats | last post by:
Hi there, I have some code for an ASP.Net page that produces an image of an e-mail address to prevent those programs that spider the net for e-mail addresses on pages grabbing it. The code is...
1
by: timtos | last post by:
I am working on a custom treeView and have some problems with a) node.Bounds.Width b) concatenate strings drawn with DrawString(...) a) I want to highlight a selected node and used the...
1
by: Drew | last post by:
I posted this to framework.drawing, but did not get any responses... Maybe here?? I am drawing some text using DrawString() and using a bounding rectangle so that when the string is too long it...
1
by: John | last post by:
I'm trying to use the DrawText() method to draw some very long string text on the Panel with AutoScroll enabled. However, for some unknown reasons, I could not trigger the ScrollBar to show up. ...
3
by: Jonah Olsson | last post by:
Hi guys! I'm trying to use Swedish characters with DrawString but no luck. Do I need to set the Charset somewhere?? I've been searching Google Groups for hours now, but I can't find any help or...
7
by: Joel Finkel | last post by:
Folks, I have a form that has several TextBoxes, some of which have the TextMode set to MultiLine. Each is pre-loaded with data from a database. The user is allowed to modify each entry. The...
1
by: johnb41 | last post by:
I need to print out a string of text and obviously i'm using the DrawString command. But the string must be placed AFTER some "programmatically generated text" (also printed using DrawString). ...
2
by: ChrisNightingale | last post by:
Hi everybody, I have an odd issue which I'm not sure how to resolve. I'm basically implementing a print mechanism which takes a series of controls and reproduces them on a print document. So...
6
by: Dilip | last post by:
Howdy Folks I have a display where the Graphics.DrawString function is called to display something. Since the text seems to be larger than its bounding rectangle, the call basically splits the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...

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.