| | |
Text Drawing questions
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2006
Posts: 131
Reputation:
Solved Threads: 0
Let me explain what I'm supposed to do first.
My assignment is to take text from a dictionary entry and display it in my client area. This dictionary entry contains characters like \ " ' and text that's written in Greek. There is an image in the upper left hand corner of the word that I'm defining and the text is supposed to flow around this image. Also, when I hover my mouse over any single word, it changes from black to red and returns to black when my mouse does not hover over it.
The way we were told to implement the text part was to construct a class containing a reference to a String and several fields, which are pretty much flags to indicate certain text properties (i.e. m_bold = 1 or 0, m_italic = 1 or 0, etc..). In our main form, we create an array of this class, and initialize the fields. Each string field is a single word from the dictionary entry and the other fields are set based on what the text looks like from the sample dictionary entry we were given. This is so that we can use the Mousemove event to do the color change.
So far, I have almost all of the requirements working. But I'm having some minor, text related problems that I can't seem to get my head around, which are part of the grading criteria. Here are my questions:
1) We were told to use the e.Graphics.MeasureString(...) method to figure out the position of the next word. The way I did this was that if my text was, say, "Hello World" (w/o the quotes), I would first draw "Hello", then call the MeasureString method, take the Width, and add that to the x position of the beginning of the word "Hello" to get the coordinates for the next word, "World". The problem is, MeasureString() tends to return a Width with some padding. My dictionary entry contains some words that have no spacing between them and when I draw all the text out, there's spacing between all of the words. How do I get rid of this padding? I tried subtracting the width a little before drawing, but that causes a bit of overlap sometimes.
2) If I have text of different sizes (i.e. 10 pt and 16 pt), how do I align their baselines so that the characters are not at the top of their cells?
My assignment is to take text from a dictionary entry and display it in my client area. This dictionary entry contains characters like \ " ' and text that's written in Greek. There is an image in the upper left hand corner of the word that I'm defining and the text is supposed to flow around this image. Also, when I hover my mouse over any single word, it changes from black to red and returns to black when my mouse does not hover over it.
The way we were told to implement the text part was to construct a class containing a reference to a String and several fields, which are pretty much flags to indicate certain text properties (i.e. m_bold = 1 or 0, m_italic = 1 or 0, etc..). In our main form, we create an array of this class, and initialize the fields. Each string field is a single word from the dictionary entry and the other fields are set based on what the text looks like from the sample dictionary entry we were given. This is so that we can use the Mousemove event to do the color change.
So far, I have almost all of the requirements working. But I'm having some minor, text related problems that I can't seem to get my head around, which are part of the grading criteria. Here are my questions:
1) We were told to use the e.Graphics.MeasureString(...) method to figure out the position of the next word. The way I did this was that if my text was, say, "Hello World" (w/o the quotes), I would first draw "Hello", then call the MeasureString method, take the Width, and add that to the x position of the beginning of the word "Hello" to get the coordinates for the next word, "World". The problem is, MeasureString() tends to return a Width with some padding. My dictionary entry contains some words that have no spacing between them and when I draw all the text out, there's spacing between all of the words. How do I get rid of this padding? I tried subtracting the width a little before drawing, but that causes a bit of overlap sometimes.
2) If I have text of different sizes (i.e. 10 pt and 16 pt), how do I align their baselines so that the characters are not at the top of their cells?
•
•
Join Date: Aug 2008
Posts: 1,735
Reputation:
Solved Threads: 186
I would be useing measurestring before drawing the first - what if the space was not sufficient for the word you have? You also dont need to measure it word by word, pass the whole string.
Assuming your font properties were all set, I wouldnt expect noticable white space, in fact, quite the reverse.
To get things base aligned, you have to use a little imagination and work out using some mathmatics. Best way for you to work it out is to draw 2 rectangles on paper give them abratrary heights and widths but sufficient to pretend they are the cells on your screen, then take smaller height values, and work out how you would know where to place the top to get the bottoms the same.
Assuming your font properties were all set, I wouldnt expect noticable white space, in fact, quite the reverse.
To get things base aligned, you have to use a little imagination and work out using some mathmatics. Best way for you to work it out is to draw 2 rectangles on paper give them abratrary heights and widths but sufficient to pretend they are the cells on your screen, then take smaller height values, and work out how you would know where to place the top to get the bottoms the same.
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
![]() |
Similar Threads
- Questions about Applet and JFrame (Java)
- Hi, caple of general questions (C#)
- Questions For WebDevelopment =) (HTML and CSS)
- Validation difficulties *sigh* (ASP.NET)
- Hello from the McGeekster (Community Introductions)
- retrieving ids from dynamically created controls in asp.net (ASP)
- NOOB question , graphical tiles (C++)
- Big Game need progrmmers (C++)
Other Threads in the C# Forum
- Previous Thread: How to save and load data to listbox in c#? pls help me! im cant solve it!
- Next Thread: Accessing form components from Thread
| Thread Tools | Search this Thread |
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# check checkbox client color combobox control conversion csharp custom data database datagrid datagridview dataset datetime degrees development draganddrop drawing encryption enum event excel file finalyearproject form format forms function gdi+ getoutlookcontactusinfcsvfile globalization httpwebrequest image index input install installer java label list listbox mandelbrot math mono mouseclick mysql operator panel path photoshop picturebox pixelinversion post programming radians regex remote remoting richtextbox serialization server silverlight sleep socket sql sql-server statistics stream string table text textbox thread time timer timespan update upload usercontrol users validate validation visualstudio webbrowser windows winforms wpf xml






