943,719 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 745
  • C# RSS
Oct 31st, 2008
0

Text Drawing questions

Expand Post »
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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster
degamer106 is offline Offline
131 posts
since Mar 2006
Nov 1st, 2008
0

Re: Text Drawing questions

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.
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: How to save and load data to listbox in c#? pls help me! im cant solve it!
Next Thread in C# Forum Timeline: Accessing form components from Thread





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC