|
-
July 23rd, 2004, 10:22 AM
#1
Making a table using SetWindowText
I am trying to display some text in my ceditview-derived class using SetWindowText. However, I want to display some coordinates in a tabular form, such as:
X Y
23.3 22.1
0.5 1.3
100.2 32.8
and so on. I was trying to using CString::Format, and like fiddling around with the precision (something like %15.3f"), but I can't seem to get it to work. Any suggestions on how I might achieve this tabular form (O, if you can't tell, I want the X and Y centered on the 2 "columns", and the numbers to be right-justified as I have tried to show, thnx).
PS: Before, I was trying to add spaces using for loops, so that in essence I was justifying it myself, but they didn't seem to work, as I think the font is not fixed-width. Maybe someone has some idea of how to change the font used by SetWindowText to a fixed-font width?
-
July 23rd, 2004, 10:44 AM
#2
Try to set a font with a fised width symbols (as Courier)
or use CRichEditView and format your text there...
As for
I was trying to using CString::Format, and like fiddling around with the precision (something like %15.3f"), but I can't seem to get it to work.
- it is not clear what does not work and what you expected from it...
-
July 23rd, 2004, 11:10 AM
#3
What I meant by it doesn't work is that the numbers are still not right justified, as I would like them to be. As for using CRichEditView, while it does have some interesting possibilities which I will make use of later, I did not find anything in it that would allow me to create columns, or tables, or the appearance of such. Perhaps you had something specific in mind?
-
July 23rd, 2004, 11:18 AM
#4
 Originally Posted by lordkelvan1
....Perhaps you had something specific in mind?
No.
However, have you already tried to use CEditView::SetTabStops ?
-
July 23rd, 2004, 11:35 AM
#5
so what ur saying is to use tabs to separate my numbers, but then depending on the "length" of the number, change the size of the tabstop right before my call to formatting (I assume tabstops means the size of '\t')? So for example, I might set the tab stop to 7 when I want to display 2.3, but set the tabstop to 5 when I want to display 2.345?
-
July 25th, 2004, 10:41 PM
#6
Could someone please help with this? I have tried using the settabstops thing, but I don't think I am using it correctly or have an incorrect understanding of what it does, as it doesn't do what it should. What I have tried to do is this:
Code:
SetTabStops(20-j);
coordinatestr.Insert(coordinatestr.GetLength()+1, '\t');
and j basically represents how many characters a particular number has (i.e. 245.23 is 6, because there are 5 digits and one decimal point). I have also tried using for loops controlled by the value of j to add spaces to the string, but the problem seems to be that the spaces (' ') are not the same size as the other characters.
As well, I tried looking at CRichEditView, and they have this property which allows you to put paragraphs side by side, but the thing is my view is suppose to be read-only, in which case how would I specify when one paragraph ends and another begins when I am outputting my data to the screen? There is also some setting for CRichEditView classes which allows you to treat the paragraph as a table row, but again there is the aforementioned problem of how to specify where paragraphs end and begin.
Is there any way to display data in a tabular format, with the data numbers right justified, the title of the two columns centered? I would be really grateful for any solution you might have.
-
July 25th, 2004, 11:47 PM
#7
If it is read only, i.e. no user interaction, then your best choice might be a CView or CScrollView. Then you have a fine degree of control and can simply use DrawText for "normal" paragrahs and TextOut to precisely line up your text in whatever font you want, instead of using a fixed font like Courier.
Steve
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|