473,406 Members | 2,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Firing an Event for a control

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.

Nov 20 '05 #1
3 2267
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.

Nov 20 '05 #2
Your post has been most helpful.

Thank You Very Much

--
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.


Nov 20 '05 #3
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.


Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: KevinRug | last post by:
I have a C# web project with a radioButtonlist control. I have 4 items/values (0,1,2,3). I am trying to retrieve the value for a database call. I put a breakpoint in the event...
2
by: Pete | last post by:
I have some funky form/event behavior. Access 97. Split frontend/backend, using Access security. I have the same behavior (or lack of behavior) for the pag_Click() event of two separate pages...
3
by: Tim Thomas | last post by:
Hi, I am very new to .NET and am in the process of building my first web application. I will briefly describe what i am trying to achieve: I have a system where suppliers register their...
1
by: Shourie | last post by:
I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle. 1) MainPage_load 2) User control1_Load user clicks a...
1
by: Earl Teigrob | last post by:
PROBLEM: When a user control is loaded into a PlaceHolder control more than once, the events do not fire on the first click of a control on the dynamically loaded user control. In other words, the...
3
by: Mike | last post by:
Hi, I am adding controls dynamically in a WebForm, but none of these controls' events fire. Here is the class code I am using. I have tried so many things, but nothing works :-( namespace...
28
by: Tim_Mac | last post by:
hi, i'm new to .net 2.0, and am just starting to get to grips with the gridview. my page has autoEventWireUp set to true, which i gather is supposed to figure out which handlers to invoke when...
5
by: Joe | last post by:
Hi I am adding a class to a ComboBox - and all is fine except that I fill the combobox on the Form_Load Method and it causes the method private void comboBox2_SelectedIndexChanged(object...
4
by: TS | last post by:
I am creating a User control and i create some dynamic controls in the init handler. one of the controls is a custom validator which i assign a serverValidate event handler. I usally always do my...
21
by: brucedodds | last post by:
I have an Access 2003 form bound to a SQL Server table via ODBC. Often clicking a button on the form has the effect of requerying the form rather than firing the OnClick event. Does anyone have...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.