I created the sub class asyour directed and added a handler for the event. I
can see that the event fires uding debug. But what happens is this.
When the RTB appears with all the text ( exceeding the height of the
control ) the scroll bars do not appear even when forced using properties.
Once the event is fired the cursor disapears due to lost focus but the text
does not scroll in the box.
Any ideas ? sorry if this sounds vague. I'm sure Im doing something wrong
but here is the code.
Public Class Form1
Inherits System.Windows.Forms.Form
Public WithEvents RTB As New MyRichTextBox
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
SetUpRTB()
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button2 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Button2 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(112, 40)
Me.Button2.Name = "Button2"
Me.Button2.TabIndex = 2
Me.Button2.Text = "Button2"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(376, 349)
Me.Controls.Add(Me.Button2)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Dim ea As New EventArgs
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
rtb.ScrollBars = RichTextBoxScrollBars.None
rtb.Text +=
"RichTextBox1jkhkhgjkhgkjjkhkjhgjghjgjkhkhgjkhgkjj khkjhgjghjgjkhkhgjkhgkjjkh
kjhgjghjgjkhkhgjkhgkjjkhkjhgjghjgjkhkhgjkhgkjjkhkj hgjghjgjkhkhgjkhgkjjkhkjhg
jghjgjkhkhgjkhgkjjkhkjhgjghjgjkhkhgjkhgkjjkhkjhgjg hjgjkhkhgjkhgkjjkhkjhgjghj
gjkhkhgjkhgkjjkhkjhgjghjgjkhkhgjkhgkjjkhkjhgjghjgj khkhgjkhgkjjkhkjhgjghjgjkh
khgjkhgkjjkhkjhgjghjgjkhkhgjkhgkjjkhkjhgjghjgjkhkh gjkhgkjjkhkjhgjghjgjkhkhgj
khgkjjkhkjhgjghJJJJJkjjkhkjhgjghjgjkhkhgjkhgkjjkhk jhgjghjgjkhkhgjkhgkjjkhkjh
gjghjgjkhkhgjkhgkjjkhkjhgjghjgjkhkhgjkhgkjjkhkjhgj ghjgjkhkhgjkhgkjjkhkjhgjgh
jgjkhkhgjkhgkjjkhkjhgjghjgjkhkhCCCCCC*******CCCCCC "
End Sub
Sub SetUpRTB()
Me.Controls.Add(Me.RTB)
Me.RTB.Location = New System.Drawing.Point(112, 144)
Me.RTB.Name = "rtb"
Me.RTB.ScrollBars = RichTextBoxScrollBars.Both
Me.RTB.Enabled = True
Me.RTB.Size = New System.Drawing.Size(208, 96)
Me.RTB.TabIndex = 0
Me.RTB.Text = ""
Me.RTB.Visible = True
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
RTB.PerformVScroll()
End Sub
Private Sub handleScroll(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles RTB.VScroll
Console.WriteLine("Handling scroll")
End Sub
End Class
--
Regards - One Handed Man
Author : Fish .NET & Keep .NET
=========================================
This posting is provided "AS IS" with no warranties,
and confers no rights.
"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:ua**************@TK2MSFTNGP12.phx.gbl...
One Handed Man,
Having a protected OnVscroll Sub to raise the VScroll Event is the
Standard .NET Event Pattern. Its recommended that you use it in classes that you
create that raise events. Especially when those classes are inheritable.
http://msdn.microsoft.com/library/de...guidelines.asp
Unless the control has an explicit public method to raise event MyEvent,
such as Button.PerformClick, the way to raise the event is to derive from
the class, then call the protected OnMyEvent method. This allows derived
controls a chance to change the behavior when the event is raised. It also
allows derived controls a chance to raise an event of the base class.
The On*event* subs are normally hidden, to see them use "Tools - Options -
Text Editor - Basic - General - Hide advanced members".
Remember only derived classes can call Protected Members.
Public Class MyRichTextBox
Inherits RichTextBox
Public Sub PerformVScroll()
MyBase.OnVScroll(EventArgs.Empty)
End Sub
End Class
Hope this helps
Jay
"One Handed Man" <te***************************@BTOpenworld.com> wrote in
message news:%2****************@TK2MSFTNGP10.phx.gbl... How can one fire an event programatically for a given control. In
another post someone wanted to cause an event in order to make a RichTextBox
scroll down.
However, the onVscroll method is a protected method for this control.
How can this be acheived. ?
Your help is appreciated. - Many Thanks
--
Regards - One Handed Man
Author : Fish .NET & Keep .NET
=========================================
This posting is provided "AS IS" with no warranties,
and confers no rights.