473,506 Members | 11,491 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to raise events programatically?

asr
I've a form with a button on it.

How to raise (I mean to run the code within the click
event of the button) without clicking the button?
Is it possible to raise the events programatically.
Nov 22 '05 #1
6 7222
"asr" <an*******@discussions.microsoft.com> wrote in news:0ba901c3a1f8
$5****************@phx.gbl:
I've a form with a button on it.

How to raise (I mean to run the code within the click
event of the button) without clicking the button?
Is it possible to raise the events programatically.


You can only raise an event from within the class itself (or a derived
class).

If you have a common method that should be run both on the click of a
button and some other instance, then put all that code within a new method.
You can call that method from both the click event and your other method...

===================================
private void Button1_Click(...)
{
SharedClickLogic();
}
private void YourOtherMethod(...)
{
SharedClickLogic();
}
private void SharedClickLogic()
{
//do stuff here
}
===================================

Michael Lang
Nov 22 '05 #2
"asr" <an*******@discussions.microsoft.com> wrote in news:0ba901c3a1f8
$5****************@phx.gbl:
I've a form with a button on it.

How to raise (I mean to run the code within the click
event of the button) without clicking the button?
Is it possible to raise the events programatically.


You can only raise an event from within the class itself (or a derived
class).

If you have a common method that should be run both on the click of a
button and some other instance, then put all that code within a new method.
You can call that method from both the click event and your other method...

===================================
private void Button1_Click(...)
{
SharedClickLogic();
}
private void YourOtherMethod(...)
{
SharedClickLogic();
}
private void SharedClickLogic()
{
//do stuff here
}
===================================

Michael Lang
Nov 22 '05 #3
Just call the name of the sub-routine in your code the way
you call any other sub, e.g.

call Button1_Click()

or

Button1_click
-----Original Message-----
I've a form with a button on it.

How to raise (I mean to run the code within the click
event of the button) without clicking the button?
Is it possible to raise the events programatically.
.


Nov 22 '05 #4
Just call the name of the sub-routine in your code the way
you call any other sub, e.g.

call Button1_Click()

or

Button1_click
-----Original Message-----
I've a form with a button on it.

How to raise (I mean to run the code within the click
event of the button) without clicking the button?
Is it possible to raise the events programatically.
.


Nov 22 '05 #5
"AlexB" <an*******@discussions.microsoft.com> wrote in news:02dd01c3a22e
$8****************@phx.gbl:
Just call the name of the sub-routine in your code the way
you call any other sub, e.g.

call Button1_Click()

or

Button1_click
-----Original Message-----
I've a form with a button on it.

How to raise (I mean to run the code within the click
event of the button) without clicking the button?
Is it possible to raise the events programatically.


Ah, but now you have to pass the sender and eventArgs which you didn't
mention in your sample.

Button1_Click(null, null); //bad practice

Be careful with this route. Creating a new common method is more clear
(see my other post).

Michael Lang, MCSD
Nov 22 '05 #6
"AlexB" <an*******@discussions.microsoft.com> wrote in news:02dd01c3a22e
$8****************@phx.gbl:
Just call the name of the sub-routine in your code the way
you call any other sub, e.g.

call Button1_Click()

or

Button1_click
-----Original Message-----
I've a form with a button on it.

How to raise (I mean to run the code within the click
event of the button) without clicking the button?
Is it possible to raise the events programatically.


Ah, but now you have to pass the sender and eventArgs which you didn't
mention in your sample.

Button1_Click(null, null); //bad practice

Be careful with this route. Creating a new common method is more clear
(see my other post).

Michael Lang, MCSD
Nov 22 '05 #7

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

Similar topics

3
459
by: asr | last post by:
I've a form with a button on it. How to raise (I mean to run the code within the click event of the button) without clicking the button? Is it possible to raise the events programatically.
0
1306
by: askingBoy | last post by:
Hello , I would like to know how to make this : I have a library written in Visual Basic .Net that has some events for its class , I am making an instance of this class in a Visual basic 6.0...
2
1895
by: Andrew | last post by:
Hi, friends, I need to raise certain events in my VC# windows control library. Any reference paper or sample source code for help? Thanks a lot...
5
2124
by: Mark Overstreet | last post by:
I am writing an app that needs to contain an object model that allows it to be controlled similiar to something like Word. However, I am writing this in C# and all managed code. I know that I can...
5
1628
by: Patrick | last post by:
Hello I have the following problem. I have an aspx Page. This page contains an ASP-Table Object. So in that table, I have a linkbutton. So, I can't edit the event of that button trough the...
2
1592
by: IcedCrow | last post by:
Subject says it all. I want to raise an event in Sub New of a class but it is not being raised to my client app. I can raise events just fine in other procedures... just not sub new. Why is...
2
2065
by: Pietro | last post by:
Hello, somebody know how to raise an event from a nested class? I have two classes, the class1 with 1 events, and a nested class (class2) inside the class1. So... How can I raise class1 events...
1
9930
by: Anonieko | last post by:
I know Visual Studio lacked support on easily writing code to raise events from a ascx user control ( because you have to hand write them)....
0
1345
by: Jose Walker | last post by:
Hi, I've an application written in ASP.NET 1.1 that uses lots of web user controls (ascx) hosted on a single page (default.aspx) which programatically loads and unloads these user controls. ...
2
2767
by: Max2006 | last post by:
Hi, We are using ASP.NET 2.0 health and monitoring provider. I know that the platform raises events automatically. I just wanted to know how can we raise them in C# code? I am trying to raise...
0
7308
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
7371
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...
1
7023
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5617
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,...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3178
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
410
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.