Help with Textbox 
Author Message
 Help with Textbox

How to get the current Char position in pixel?
I dont know which messages should I send to it and how to do.


Mon, 21 Jan 2002 03:00:00 GMT  
 Help with Textbox
Hi,

Try the following smaple:

1. Open a new project and place a Text1 textbox on it.
2. Make the Text1. Multiline=True
3. Copy the following code to Form1:

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
(ByVal hWnd As Long, ByVal wMsg As Long, wParam As Long, lParam As Any)
As Long

Private Const EM_POSFROMCHAR = &HD6

Private Sub Text1_Click()
    Dim nX As Integer
    Dim nY As Integer

    Call GetCharPos(Text1.hWnd, Text1.SelStart, nX, nY)

    Debug.Print "X = "; nX; "  Y = "; nY
End Sub
Private Sub GetCharPos(ByVal hWnd As Long, ByVal lCharPos As Long, nX As
Integer, nY As Integer)
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'Returns the X and Y coordinates of the char at position'
    'specified by lCharPos.                                 '
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'NOTE: nX and nY coordinates are in pixels.             '
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'INPUT:                                                 '
    '       lCharPos - long, 0-based index of character in  '
    '                  an Edit or Rich Edit control.        '
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'OUTPUT:                                                '
    '       nX - integer, X coordinate, in pixels of the    '
    '            char.                                      '
    '       nY - integer, Y coordinate, in pixels of the    '
    '            char.                                      '
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Dim lRetVal As Long
    Dim lPos As Long
    Dim lParam As Long

    lPos = lCharPos

    lRetVal = SendMessage(hWnd, EM_POSFROMCHAR, ByVal lPos, ByVal
lParam)

    nX = lRetVal And &HFFFF&
    nY = (lRetVal \ &H10000) And &HFFFF
End Sub

4. Run the project and paste some text in the Textbox and then click
somewhere over the text.
   X and Y coordinates in pixels will be printed in the Debug window.

Regards,
         Stoil

Quote:

> How to get the current Char position in pixel?
> I dont know which messages should I send to it and how to do.



Mon, 21 Jan 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Help! Need help with TextBox Cntrl

2. Help in Textbox

3. Help with textbox/rich scrolling to a position

4. HELP Formatting TextBox for whole numbers

5. need help with textbox validation problem

6. Help with textbox & date please

7. Newbie Needs Help on Textbox

8. Newbie needs help with TextBox

9. Please help with TextBox / Label properties

10. Help: Custom TextBox and ComboBox control issue

11. Help with TextBox

12. help with textbox

 

 
Powered by phpBB® Forum Software