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

    Displaying on a form

    Hi,

    I am new to VB, can anyone help me regarding the following:

    I have a form, i want to divide it into 32 columns and 16 rows. Based on the requirement i want to display on the co-ordinates say (16th column,5th row) some text on the form.

    Please note that we are not using mouse for this application.

    thanks in advance.


    Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Displaying on a form

    FlexGrid or MSFlexGrid
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Mar 2011
    Posts
    7

    Question Re: Displaying on a form

    Hi dglienna,

    Thanks for your reply . I guess it will not match my requirement. My requirement is something like this I want to display a frame(with black background) and on that i need to display the text i don't want the grid to be displayed.

    The text to be dispaly can be in different positions.

    Just an example


    (Row, Column) - text to be dispalyed on the form


    (4,10) - WELCOME

    (5,12)- TO

    (6,8)- FORM


    The output will be as below
    **************


    WELCOME
    TO
    FORM



    **************

    Is there any other way to do this ??

    Thanks in advance...

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Displaying on a form

    You could use the Print method, but that doesn't really offer you much power in setting where to print the text onto the form, but in any case, here's an example :

    Code:
    Print "test"' writes the word 'test' on form
    Your'e best bet would be to use the DrawText API. Copy this into a new form :

    Code:
    Option Explicit
    Private Type RECT
            Left As Long
            Top As Long
            Right As Long
            Bottom As Long
    End Type
    
    Private Declare Function DrawText Lib "user32" Alias "DrawTextA" (ByVal hDC As Long, ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long
    Private Const DT_WORDBREAK = &H10
    
    Private Sub Command1_Click()
    
    Dim rct As RECT
    
    Me.ScaleMode = vbPixels
    
    With rct
        .Left = 4
        .Right = Me.ScaleWidth
        .Top = 10
        .Bottom = Me.ScaleHeight
    End With
    
    DrawText Me.hDC, "WELCOME", -1, rct, DT_WORDBREAK 'can use textbox here or whatever instead of "WELCOME"
    
    
    With rct
        .Left = 20
        .Right = Me.ScaleWidth
        .Top = 30
        .Bottom = Me.ScaleHeight
    End With
    
    DrawText Me.hDC, "TO", -1, rct, DT_WORDBREAK
    
    With rct
        .Left = 40
        .Right = Me.ScaleWidth
        .Top = 60
        .Bottom = Me.ScaleHeight
    End With
    
    DrawText Me.hDC, "FORM", -1, rct, DT_WORDBREAK
    End Sub

  5. #5
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Displaying on a form

    If you use a RTB (Rich Text Box), you can draw text at screen positions.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  6. #6
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Displaying on a form

    With the DrawText API, anything is possible

  7. #7
    Join Date
    May 2009
    Location
    London
    Posts
    51

    Re: Displaying on a form

    An alternative, is to have a multi line textbox on the frame filled with spaces corresponding to the number of rows/columns required. Then you can use string manipulation to implant text into the textbox. The textbox has to be set to a non-proportional font (for instance Courier).

    See attached file for example.
    Attached Files Attached Files

  8. #8
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Thumbs up Re: Displaying on a form

    Quote Originally Posted by dglienna View Post
    If you use a RTB (Rich Text Box), you can draw text at screen positions.
    Quote Originally Posted by Killa69 View Post
    An alternative, is to have a multi line textbox on the frame filled with spaces corresponding to the number of rows/columns required. Then you can use string manipulation to implant text into the textbox. The textbox has to be set to a non-proportional font (for instance Courier).

    See attached file for example.
    OK, the lights inside my head went on now. Good work guys!

  9. #9
    Join Date
    Aug 2009
    Posts
    100

    Re: Displaying on a form

    Haven't used it in a while, but doesn't MSFlexGrid have a property that can be set to not show the gridlines?

  10. #10
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Displaying on a form

    Yes.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

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