I am trying to draw lines to seperate sections in a RichTextBox
except the lines do not stay after scrolling off the screen.
So should I capture the scroll event and redraw or is there a better way?
if not.. how do I capture the scroll event?
thanks!
check for the previos scroll value and compare with the new value - if there is any change in these two values then the scroll occured in the rich text box... hope this will help u
You can generate your own scroll event
send a EM_SETEVENTMASK message to your rtb to set the mask for EN_VSCROLL notification.
Then subclass your main window and trap WM_COMMAND messages
when EN_VSCROLL comes up the user has scrolled
If you just redraw the lines during scrolling there shouldn't be too much flicker, if there is you can do a double buffer. http://msdn.microsoft.com/library/d...eteventmask.asp
moeur, yes... but I cant find any good code examples! I Need an example to be able to change / learn how to use EM_SETEVENTMASK etc..
CANT FIND ANY!!
dglienna.. I dont want to use an underline because then it will save into the file..(This is for the CodeBank app.. the underline will become part of the code snippet)
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
not saving as rtf.. just the text..
I would rather not have to remove before save...
and I dont want the user to be able to highlight / edit / change the line...
if they do.. then it would be hard to remove it from the text before save...
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
Are you worried that if the user edits a line that has an underline then the new text won't be underlined? If so, then you could handle that pretty easily by putting some code in the selchange event to underline new text when the cursor is in the special underlined region.
no , I just dont want the user to be able to interact with the lines at all.. as iff they dont exist.. just like in VB IDE. there are line seperating the subs etc.. but you cant touch them
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
OK, here is something. For some stupid reason, the EN_VSCROLL notification is not sent when the user drags the thumb. So I had to also subclass the form to catch those messages.
In a module define these public routines
VB Code:
Option Explicit
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 Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" ( _
ByVal lpPrevWndFunc As Long, _
ByVal hWnd As Long, _
ByVal Msg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long _
) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private Const WM_USER = &H400
Private Const EN_HSCROLL = &H601
Private Const EN_VSCROLL = &H602
Private Const EN_CHANGE = &H300
Private Const EN_UPDATE = &H400
Private Const EM_SETEVENTMASK = (WM_USER + 69)
Private Const ENM_SCROLL = &H4
Private Const EM_GETSCROLLPOS = (WM_USER + 221)
Private Const EM_SETSCROLLPOS = (WM_USER + 222)
Private Const WM_COMMAND = &H111
Private Const WM_VSCROLL = &H115
Private Const WM_HSCROLL = &H114
'Must be declared in BAS file not FRM file.
Public frmSubClass As CSubclass
Public RTBsubClass As CSubclass
Public Function NewFrmWndProc(ByVal hWnd As Long, ByVal uMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
'This is where the messages for our Form will arrive
Re: [RESOLVED] Capture Scroll Event of RichTextBox
I am developing a WYSIWYG editor for this forum which uses a richtextbox so I am going to need something similar to your request. I think this method of inserting a separator line is much better no subclassing or tracking involved.
VB Code:
Public Sub Separator(rtb As RichTextBox, lColor As Long)
I'll continue to improve this code, but wanted to get it to you incase you'd rather use it.
I also have code for highlighting and super/sub-scripts too if you need that.
Re: [RESOLVED] Capture Scroll Event of RichTextBox
Here is a better looking separator routine.
The beauty of this routine is that it inserts a seperator that looks nice, scrolls properly and the user cannot access. The one problem is that you will have to remove it before saving, but that is easily handled with a call to replace.
Use the above (fixed) colortable function and this new separator routine
VB Code:
Public Sub Separator(rtb As RichTextBox, lColor1 As Long, _
lColor2 As Long, halfWidth As Integer, txtTitle As String)
Re: [RESOLVED] Capture Scroll Event of RichTextBox
ok, your going to be mad.. but I've found after all that. The code for putting lines in and keep them, seems to be interfering with other code!!
Not sure why.. example: RichTextBox_Change event no longer gets fired...
my auto indent code is adding extra #'s to the selstart location so it moves it when done.. etc.
I removed all the code/ module/ cls and it works fine..
I was concentrating so much on the lines.. I never tried other code until the lines worked right....I may go back to your other code.. need to play more
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"