Hai,
I Am Doing A Project In VB 6.0 IN Which I AM USING A RICH TEXT BOX TheN I HAVE TO DISPLAY A Listbox WITH LIST ITEMS IN IT At The Cursor Position When Ever A Space Is Encounterd
Can Any One Suggest
Printable View
Hai,
I Am Doing A Project In VB 6.0 IN Which I AM USING A RICH TEXT BOX TheN I HAVE TO DISPLAY A Listbox WITH LIST ITEMS IN IT At The Cursor Position When Ever A Space Is Encounterd
Can Any One Suggest
Where the space will be encountered?
Sort of intellisense I might guess.
I'm not sure this will work, but here's some "pseudocode". Write a looping routine using INSTR to locate blanks in the .Text string property of the rich text box. When found, initialize an array pointer equal to the value returned by INSTR as it moves along the .Text string.
Count the number of blank hits. When INSTR returns a zero, no blanks are left. Now add all the values you found in the array that you counted to the list box to display them.
I Didn't Understand It Clearly Can U Explain It Clearly
Read up on InStr() function so you'll understand what it is for.
might help if you expand on what you do or would like to do with it?
Is this is what your looking for?
It reads a string from a textbox and adds the position of all the spaces to a listbox.
Code:Dim str1 As String
str1 = Text1.Text
Dim i As Long
For i = 1 To Len(str1)
If Mid$(str1, i, 1) = " " Then
List1.AddItem i
End If
Next
...or do you mean something like this ?
(Add a RichTextBox and a ListBox in a form and paste this code)
vb Code:
' Add a RichTextBox and a ListBox in a form and paste this code Option Explicit Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" ( _ ByVal hwnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ ByRef lParam As Any) As Long Private Const WM_USER As Long = &H400 Private Const EM_POSFROMCHAR As Long = (WM_USER + 38) Private Sub ShowListBox() Dim pos As Long Dim x As Long Dim y As Long pos = SendMessage(RichTextBox1.hwnd, EM_POSFROMCHAR, RichTextBox1.SelStart, 0) Me.Font.Name = RichTextBox1.SelFontName Me.Font.Size = RichTextBox1.SelFontSize x = LoWord(pos) * Screen.TwipsPerPixelX + RichTextBox1.Left y = HiWord(pos) * Screen.TwipsPerPixelY + RichTextBox1.Top + Me.TextHeight("H") + 25 List1.ListIndex = 0 List1.Move x, y List1.Visible = True List1.ZOrder 0 List1.SetFocus End Sub Function LoWord(DWord As Long) As Integer If DWord And &H8000& Then ' &H8000& = &H00008000 LoWord = DWord Or &HFFFF0000 Else LoWord = DWord And &HFFFF& End If End Function Function HiWord(DWord As Long) As Integer HiWord = (DWord And &HFFFF0000) \ &H10000 End Function Private Sub Form_Load() Dim i As Long With List1 For i = 1 To 25 .AddItem CLng(Rnd * 100000) Next .Width = 1440 .Visible = False End With End Sub Private Sub List1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then RichTextBox1.SelText = List1.Text List1.Visible = False RichTextBox1.SetFocus ElseIf KeyAscii = vbKeyEscape Then List1.Visible = False RichTextBox1.SetFocus End If End Sub Private Sub RichTextBox1_KeyPress(KeyAscii As Integer) If KeyAscii = 32 Then ShowListBox Else List1.Visible = False RichTextBox1.SetFocus End If End Sub
Me and others already have replied in your other thread.
Please DO NOT CREATE DUPLICATE THREADS.
If you think your thread title is inappropriate, click the Edit button http://www.vbforums.com/images/buttons/edit.gif in the first post and change the title. :)
Like Intellisense In Rich Text Box
Try my code in post#8.
Duplicate threads merged.
Please do not post the same question in multiple threads.
Float the listbox (.visible = true) at relevant position whenever space is pressed (keypress/keydown event). Hide the listbox (.visible = false) when it loses focus (other controls clicked, TAB pressed), user selects a listitem (RTB selstart, seltext updated accordingly) , or user cancels/presses ESC.
Ok Thread Is Resolved Thanks For All
If you think this thread is resolved, could you please do us a little favour, and mark this thread as Resolved?
(this saves time reading for those of us who like to answer questions, and also helps those who search to find answers)
You can do this by clicking on "Thread tools" just above the first post in this thread, then "Mark thread resolved".
Also, if you think anyone was particularly helpful (or particularly unhelpful!) you can Rate their post by clicking the link under their name. For more info, see here