CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2004
    Posts
    148

    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?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430
    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...

  3. #3
    Join Date
    Jul 2004
    Posts
    148
    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?

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430
    Quote Originally Posted by lordkelvan1
    ....Perhaps you had something specific in mind?
    No.
    However, have you already tried to use CEditView::SetTabStops ?

  5. #5
    Join Date
    Jul 2004
    Posts
    148
    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?

  6. #6
    Join Date
    Jul 2004
    Posts
    148
    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.

  7. #7
    Join Date
    Sep 1999
    Location
    Colorado, USA
    Posts
    1,002
    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
  •  





Click Here to Expand Forum to Full Width

Featured