|
-
Jul 16th, 2008, 06:39 PM
#1
Thread Starter
New Member
Realtime richtext box updating while editing
Hello, I am glad to have come across a seamingly helpful community as this one! I am a vb 6 devoloper and a few friends and i are currently stumped on an interesting problem. We need to create a rich text box that can be updated while a user is typing somewhere else in the document. Pretty much we need to update text that is not at the cursor. We have created our own user control, but still havent been able to figure out how to do that.
weve briefly looked into data grid controls but they do not have the formatting we are looking for and ultimatly just isnt as clean.
Any help is muchly appreciated. Thanks!
-
Jul 16th, 2008, 08:40 PM
#2
Re: Realtime richtext box updating while editing
try this
Private Sub Text3_KeyPress(KeyAscii As Integer)
With rtb
.SelText = .SelText & Chr(KeyAscii)
End With
End Sub
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders 
-
Jul 17th, 2008, 12:40 AM
#3
Thread Starter
New Member
Re: Realtime richtext box updating while editing
Thanks for the help. Unfortunately that will not work because we want to make it so that the text in the same rich text box can change dynamically while still having the user to be possibly typing at the time. For example, there is a timer that adds a "+" at the beginning of the rich text box every second, but we are having problems with when typing in the textbox and that timer fires with displaying correctly. We don't want the cursor to have to jump back to the beginning of the rich text box to add the "+" and interfere with the user entering text into the rich text box.
Again thanks for your thoughts, any help is muchly appreciated!
-
Jul 17th, 2008, 01:27 AM
#4
Re: Realtime richtext box updating while editing
In the timer event, write a line a of code after the code for "+".
Code:
Text1.selstart=len(Text1.text)
Not sure, but just try it. It will place the cursor at the end of the TextBox, so the user can continue typing.....
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Jul 17th, 2008, 02:44 AM
#5
Re: Realtime richtext box updating while editing
Humm, I guess this would be considered a flaw in the standard richtextbox control as it lacks a feature that can be found in the RichEdit control that it implements. There are alternative solutions that allow to use a Range to modify text anywhere in the textbox without it interrupting anything, not causing screen to scroll or blink etc. - too bad that would mean downloading some other OCX that may have other flaws.
Anyways, the way to go with SelText:
Code:
Private Sub Timer1_Timer()
Dim lngSelStart As Long, lngSelLen As Long
lngSelStart = RichTextBox1.SelStart + 1
lngSelLen = RichTextBox1.SelLength
RichTextBox1.SelStart = 0
RichTextBox1.SelText = "+"
RichTextBox1.SelStart = lngSelStart
RichTextBox1.SelLength = lngSelLen
End Sub
-
Jul 20th, 2008, 01:35 PM
#6
Thread Starter
New Member
Re: Realtime richtext box updating while editing
hmmm... ok, thank you everybody for your suggestions. The method described would work with it jumping back to the end, but we are somewhat afraid after the number of lines increases the process is going to become slower and slower to the point of a nuissance to the end user. Does anyone have any ideas what other ocx's are out there that might work? I thought about creating my own, but I haven't been able to find much on how to create my own richtext box giving me the ability to add such a feature.
Again, thanks for the suggestions!
-
Jul 20th, 2008, 01:55 PM
#7
Re: Realtime richtext box updating while editing
This seems working.
Needed to add a LockWindowUpdate and EM_GETSCROLLPOS/EM_GETSCROLLPOS to get/set current scrolling position of RTB. It flickers a little (due to the call to LockWindowUpdate).
vb Code:
Option Explicit
Private Const WM_USER As Long = &H400
Private Const EM_GETSCROLLPOS As Long = (WM_USER + 221)
Private Const EM_SETSCROLLPOS As Long = (WM_USER + 222)
'
Private Type POINT
X As Long
Y As Long
End Type
'
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 Declare Function LockWindowUpdate _
Lib "user32" (ByVal hwndLock As Long) As Long
Private Sub Timer1_Timer()
Dim lngSelStart As Long, lngSelLen As Long
Dim CurrentPos As POINT
'
LockWindowUpdate RichTextBox1.hwnd
SendMessage RichTextBox1.hwnd, EM_GETSCROLLPOS, 0, CurrentPos ' Get current scrolling position
'
lngSelStart = RichTextBox1.SelStart + 1
lngSelLen = RichTextBox1.SelLength
RichTextBox1.SelStart = 0
RichTextBox1.SelText = "+"
RichTextBox1.SelStart = lngSelStart
RichTextBox1.SelLength = lngSelLen
'
SendMessage RichTextBox1.hwnd, EM_SETSCROLLPOS, 0, CurrentPos
LockWindowUpdate 0
End Sub
-
Jul 20th, 2008, 05:40 PM
#8
Re: Realtime richtext box updating while editing
It would be cleaner to make a call to WM_SETREDRAW to disable the painting temporarily. I'll see if I make a sample later, now I have to eat.
-
Jul 20th, 2008, 06:36 PM
#9
Re: Realtime richtext box updating while editing
Here:
Code:
Option Explicit
Private Declare Function InvalidateRect Lib "user32" (ByVal hWnd As Long, ByVal lpRect As Long, ByVal bErase As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_SETREDRAW = &HB&
Private Sub Timer1_Timer()
Dim lngSelStart As Long, lngSelLen As Long, lngScrollPos(1) As Long
SendMessage RichTextBox1.hWnd, WM_SETREDRAW, 0, ByVal 0&
lngSelStart = RichTextBox1.SelStart + 1
lngSelLen = RichTextBox1.SelLength
RichTextBox1.SelStart = 0
RichTextBox1.SelText = "+"
RichTextBox1.SelStart = lngSelStart
RichTextBox1.SelLength = lngSelLen
SendMessage RichTextBox1.hWnd, WM_SETREDRAW, -1&, ByVal 0&
InvalidateRect RichTextBox1.hWnd, 0, 0
End Sub
No blinking. But the scroll issue remains. EM_GETSCROLLPOS and EM_SETSCROLLPOS are not enough. One should also find out whether the view is at the bottom or not before using them, because otherwise it just gets stuck in the beginning.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|