473,396 Members | 1,913 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,396 software developers and data experts.

Raising event

I want to raise an event (not call event handler!!) of a control. I have a
control and I need to raise it's Enter event programmatically so that
control will then call all it's Enter event handlers. I searched but
couldn't find anything and I can't call an event directly. I have to do this
because I need it when user switches between forms. In such a case, Enter
event is raised only on form getting focus but not on child control that is
focused. In Win32 I could at least send a message but I don't wanna use
messages in C#. I want a more .NET approach :).

regards
Tomaz
Nov 17 '05 #1
4 1817
Tomaz,

You can't do this (it is considered a breach of security if you could).
If the control does not expose a method that will allow you to fire this,
then you won't be able to do it.

The only workaround I can think of would be to use reflection to get the
delegate stored internally, or to send a windows message to the control to
make it think it has to fire the event.

Or, you could create a control that derives from the appropriate control
and expose a method which will fire the event and use that where you need
to.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Tomaz Koritnik" <no****@nospam.com> wrote in message
news:OM****************@news.siol.net...
I want to raise an event (not call event handler!!) of a control. I have a
control and I need to raise it's Enter event programmatically so that
control will then call all it's Enter event handlers. I searched but
couldn't find anything and I can't call an event directly. I have to do
this because I need it when user switches between forms. In such a case,
Enter event is raised only on form getting focus but not on child control
that is focused. In Win32 I could at least send a message but I don't wanna
use messages in C#. I want a more .NET approach :).

regards
Tomaz

Nov 17 '05 #2
Just a quick note
You could also use reflection to access the protected method OnEnter and
invoke it. It fires the event.
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:Ow**************@TK2MSFTNGP12.phx.gbl...
Tomaz,

You can't do this (it is considered a breach of security if you could). If the control does not expose a method that will allow you to fire this,
then you won't be able to do it.

The only workaround I can think of would be to use reflection to get the delegate stored internally, or to send a windows message to the control to
make it think it has to fire the event.

Or, you could create a control that derives from the appropriate control and expose a method which will fire the event and use that where you need
to.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Tomaz Koritnik" <no****@nospam.com> wrote in message
news:OM****************@news.siol.net...
I want to raise an event (not call event handler!!) of a control. I have acontrol and I need to raise it's Enter event programmatically so that
control will then call all it's Enter event handlers. I searched but
couldn't find anything and I can't call an event directly. I have to do
this because I need it when user switches between forms. In such a case,
Enter event is raised only on form getting focus but not on child control
that is focused. In Win32 I could at least send a message but I don't wannause messages in C#. I want a more .NET approach :).

regards
Tomaz


Nov 17 '05 #3
As Nicholas pointed out, the .NET designers went to great lengths to
make this near-impossible to do. There is probably a very good reason
for this.

This is one of those points at which you should post more details about
the problem you're trying to solve, rather than the solution you've
come up with (get the control to fire its Enter event... for what
purpose?) so we can suggest design alternatives.

Nov 17 '05 #4
As I said, I have several MDI forms wth controls on them and when form gets
focus, the control that also receives focus will not raise Enter event. I
need this in order to greatly simplify my code. I solved the problem by
using reflections and I'm calling OnEnter of the control to make it work.
It's not a bad design but if I would have to do it other way the design
would be more difficult. Also, I can't make descendants as many different
types of controls are used (text box, combo, list, grid,...) and I would
have to do lots of work to use my new controls in designe-mode.

regards
Tomaz
"Bruce Wood" <br*******@canada.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
As Nicholas pointed out, the .NET designers went to great lengths to
make this near-impossible to do. There is probably a very good reason
for this.

This is one of those points at which you should post more details about
the problem you're trying to solve, rather than the solution you've
come up with (get the control to fire its Enter event... for what
purpose?) so we can suggest design alternatives.

Nov 17 '05 #5

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

Similar topics

5
by: Santhoshi | last post by:
I have an event declared in class1 Now i want to raise the event in the my class2 or anywhere other than class1 Is it possible? If so how Thank you
1
by: Rajesh.V | last post by:
I have made a custom control in asp.net using webcontrols, and am raising my event. I find that if no control is hooked into the event it goes for a toss. I tried to find length of the delegate...
6
by: Dan | last post by:
I've created a pocketpc app which has a startup form containing a listview. The form creates an object which in turn creates a System.Threading.Timer. It keeps track of the Timer state using a...
4
by: rawCoder | last post by:
Hi all, How Can You Raise Events Asynchronously ? Now for the details ... I want to do inter modular communication using events in such a way that the contributing modules need not...
0
by: Joe Campbell | last post by:
I am encountering a problem raising WMI events from an asp.net application. The error received (as captured in the event log) is as follows: System.Runtime.InteropServices.COMException...
4
by: Dave A | last post by:
I am developing a somewhat complex component at the moment and coincidently I am also reading the Framework Design Guidelines book. After reading the section about event raising I have re-written...
2
by: Gman | last post by:
Hi, I have created a usercontrol, a grid control essentially. Within it I have a class: clsGridRecord. I have coded the events such that when a user clicks on the grid, say, the events occur on...
4
by: sloan | last post by:
I"m trying to figure out what concept I'm missing here, or if its not a good idea .. or what. Here is my example.. code is below. I have an employee class. It has an event that can be raised....
2
by: =?Utf-8?B?Um9i?= | last post by:
I'm new to event processing in vs 2005 - what I'm trying to achieve is broadly a network simulation of two workstations sending packets to each other . I have defined a class 'Workstation' and I...
7
by: Christian Cambier | last post by:
Hi, I have a textbox in a web user control. I then add the usercontrol to a web form. I also add a label in the web form. Now, when I press a key in the textbox, i want to display some text...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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.