473,662 Members | 2,693 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 7241
"asr" <an*******@disc ussions.microso ft.com> wrote in news:0ba901c3a1 f8
$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(. ..)
{
SharedClickLogi c();
}
private void YourOtherMethod (...)
{
SharedClickLogi c();
}
private void SharedClickLogi c()
{
//do stuff here
}
=============== =============== =====

Michael Lang
Nov 22 '05 #2
"asr" <an*******@disc ussions.microso ft.com> wrote in news:0ba901c3a1 f8
$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(. ..)
{
SharedClickLogi c();
}
private void YourOtherMethod (...)
{
SharedClickLogi c();
}
private void SharedClickLogi c()
{
//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*******@disc ussions.microso ft.com> wrote in news:02dd01c3a2 2e
$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(n ull, 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*******@disc ussions.microso ft.com> wrote in news:02dd01c3a2 2e
$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(n ull, 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
1313
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 Project and I can call the methods from the object I instanced . However I cannot raise the events from this library with my object , I already made a sub in the vb 6.0 in the form : Private Sub object_Event() 'Some code here End Sub
2
1910
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
2131
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 use remoting to talk to the UI components but I need an example of how to create an event when something happens on the UI (e.g. text box receives focus) and fire that via my object model back to any remote client. I also need the ability to...
5
1635
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 WYSIWYG editor, so I co to the CodeBehind and add the Event in the InitializeComponent() Method like this this.lbTest.Click += new System.EventHandler(this.lbTest_Click); so far, all works fine. now if i go to the WYSIWYG editor, add another...
2
1596
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 this? Thanks in advance!
2
2077
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 from the class2? Public Class class1 Public Shared Event Evento1(ByRef sender As Object) Public Class class2
1
9935
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). (http://codebetter.com/blogs/brendan.tompkins/archive/2004/10/06/27795.aspx) Question: Is it better and easier now in ASPNET 2.0 , meaning VS 2005?
0
1348
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. In ASP.NET 1.1 all events postbacks where properly working, once the application is moved ASP.NET 2.0 these events are not raised anymore! I've taken the time to thru the whole application and migrate it properly to
2
2776
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 WebBaseErrorEvent or WebManagementEvent. Thank you, Max
0
8435
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8857
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8768
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8547
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6186
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5655
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4348
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2763
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1999
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.