home *** CD-ROM | disk | FTP | other *** search
- VERSION 2.00
- Begin Form Form1
- Caption = "Form1"
- ClientHeight = 4020
- ClientLeft = 225
- ClientTop = 1485
- ClientWidth = 6630
- Height = 4425
- Left = 165
- LinkTopic = "Form1"
- ScaleHeight = 4020
- ScaleWidth = 6630
- Top = 1140
- Width = 6750
- Begin Timer Timer1
- Interval = 100
- Left = 3720
- Top = 120
- End
- Begin TextBox Text2
- Height = 285
- Left = 4440
- TabIndex = 2
- Text = "Click to change focus."
- Top = 1560
- Width = 2055
- End
- Begin CommandButton Command1
- Caption = "Exit"
- Height = 375
- Left = 4440
- TabIndex = 1
- Top = 1080
- Width = 1095
- End
- Begin TextBox Text1
- Height = 3015
- Left = 480
- MultiLine = -1 'True
- TabIndex = 0
- Text = "Text1"
- Top = 840
- Width = 3855
- End
- Begin Label Label5
- Height = 255
- Left = 1440
- TabIndex = 6
- Top = 480
- Width = 495
- End
- Begin Label Label4
- Caption = "Line No.:"
- Height = 255
- Left = 480
- TabIndex = 5
- Top = 480
- Width = 855
- End
- Begin Label Label3
- Caption = "Character:"
- Height = 255
- Left = 480
- TabIndex = 4
- Top = 120
- Width = 855
- End
- Begin Label Label2
- Height = 255
- Left = 1440
- TabIndex = 3
- Top = 120
- Width = 615
- End
- 'API function declarations needed to get line number
- Declare Function GetFocus Lib "user" () As Integer
- Declare Function SendMessage Lib "user" (ByVal a%, ByVal b%, ByVal c%, ByVal d As Any) As Long
- Sub Command1_Click ()
- End Sub
- Sub Form_Load ()
- thetext$ = "This is a demonstration of getting the current cursor position and line number from a text box control. "
- thetext$ = thetext$ + "Formerly, in VB 1.0, it was almost impossible to always know which line the cursor was on when "
- thetext$ = thetext$ + "focus switched from another control to the text box. To see how this works, click on the box to "
- thetext$ = thetext$ + "the right, then click again, anywhere inside this text box, or type in the box."
- text1.Text = thetext$
- End Sub
- Function GetLineNo (charpos&)
- 'Set constant value
- Const EM_linefromchar = &H400 + 25
- 'Get current line number from cursor position
- pos% = 1 + SendMessage(GetFocus(), EM_linefromchar, -1, 0&)
- 'Assign return value to function
- GetLineNo = pos%
- End Function
- Sub Text1_GotFocus ()
- timer1.interval = 100 'Sets timer interval to .1 sec.
- timer1.Enabled = True 'activates timer routine to get line number when edit control has focus.
- End Sub
- Sub Text1_LostFocus ()
- timer1.Enabled = False 'disables timer when focus is lost.
- End Sub
- Sub Timer1_Timer ()
- label2.Caption = text1.SelStart 'gets character position
- pos& = text1.SelStart 'assign to variable
- currline = GetLineNo(pos&) 'calls linenumber function
- label5.Caption = currline 'displays current line number
- End Sub
-