Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / September 2004

Tip: Looking for answers? Try searching our database.

How to manualy initiate the event?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Haim - 27 Sep 2004 13:39 GMT
Hi,
I would like to know if there in C# an equivalent to the
VB.NET RaiseEvent statement.

I would like to raise an event of a control in my code as
if the user's action provoked it.

Thanks,

Haim.
Peter Jausovec - 27 Sep 2004 14:29 GMT
Hi,

You can call the event handler method.

Regards,
Peter

> Hi,
> I would like to know if there in C# an equivalent to the
[quoted text clipped - 6 lines]
>
> Haim.
haim - 27 Sep 2004 14:47 GMT
Hi,
It would help me a lot if you kindly write a small
example.

Thanks,

Haim.

>-----Original Message-----
>Hi,
[quoted text clipped - 16 lines]
>
>.
Peter Jausovec - 27 Sep 2004 15:04 GMT
Sure. E.g. :

private void button_Click(object sender, System.EventArgs e)
{
   // do something here
}

private void RaiseTheEvent (...)
{
   button_Click (this, System.EventArgs)
}

> Hi,
> It would help me a lot if you kindly write a small
[quoted text clipped - 26 lines]
> >
> >.
Haim - 27 Sep 2004 15:24 GMT
My question was - if you have a control with a given set
of events, like a notifyIcon that displayes the text only
when on the mouse hover event, its not me who wrote this
event function (it is a part of the given control and I
have no access to it) so I can't call it.
I would like to trigger the mouse hover event of a
notifyIcon (for example) at my will and not only when the
user activate it.

Is there a way?

>-----Original Message-----
>Sure. E.g. :
[quoted text clipped - 41 lines]
>
>.
Peter Jausovec - 27 Sep 2004 16:01 GMT
If I understand you're trying to show the tooltip for e.g. notifyIcon
programmatically ?

> My question was - if you have a control with a given set
> of events, like a notifyIcon that displayes the text only
[quoted text clipped - 54 lines]
> >
> >.
Haim - 28 Sep 2004 08:12 GMT
But this is only a small example for a need of this kind.
In VB.NET the RaiseEvent statement solve this problem, I
thought there must be an equivalent in C#...

Thanks again,

Haim.

>-----Original Message-----
>If I understand you're trying to show the tooltip for e.g. notifyIcon
[quoted text clipped - 60 lines]
>
>.
Morten Wennevik - 27 Sep 2004 15:10 GMT
Hi haim,

If you have a MouseDown event like this

private void MyControl_MouseDown(object sender, MouseEventArgs e)
{
}

then you can call this directly with

MyControl_MouseDown(MyControl, new MouseEventArgs(MouseButtons.Right, 1, x, y, 0));

To indicate that the user clicked once on MyControl in location (x, y);

Signature

Happy coding!
Morten Wennevik [C# MVP]

- 27 Sep 2004 15:27 GMT
Please see my above reply to Peter, your solution does
not help me...

>-----Original Message-----
>Hi haim,
[quoted text clipped - 10 lines]
>
>To indicate that the user clicked once on MyControl in location (x, y);
Sijin Joseph - 27 Sep 2004 15:05 GMT
Let's suppose you have an event called DirtyChanged in your class, here
is how you would raise the event using C#

public class EventTester
{
    public event EventHandler DirtyChanged;

    public void RaiseDirtyChangedEvent()
    {
        //The check is required because if no event handlers are
                //attached to the event then the next line will throw a
                //NullReferenceExcpetion

        if(DirtyChanged != null)
            DirtyChanged(this,new EventArgs());
    }
}

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph

> Hi,
> I would like to know if there in C# an equivalent to the
[quoted text clipped - 6 lines]
>
> Haim.
- 27 Sep 2004 15:28 GMT
your solution does not help me. Please see my reply to
peter with subject: "OK, I knew that already".

Thanks,

Haim.

>-----Original Message-----
>Let's suppose you have an event called DirtyChanged in your class, here
[quoted text clipped - 31 lines]
>>
>.
Sijin Joseph - 28 Sep 2004 07:15 GMT
Hi Haim,

There is no clean way to do this other than deriving from the control.
But there is a hack that you could use, using reflection. To fire the
event you need to call the control OnXXX() methods for the corresponding
 event. For e.g to fire the Hover event of the button control you will
need to call the OnMouseHover protected method of the button class.

Here is a sample code i wrote to invoke the click event of a button

MethodInfo mi =
this.button1.GetType().GetMethod("OnClick",BindingFlags.Instance|BindingFlags.NonPublic);
            if(mi != null)
                mi.Invoke(button1,new object[]{new EventArgs()});

Hope that helps.

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph

> your solution does not help me. Please see my reply to
> peter with subject: "OK, I knew that already".
[quoted text clipped - 56 lines]
>>
>>.
Haim - 28 Sep 2004 08:43 GMT
Reflection is a great idea! don't know how I didn't think
about it myself :-)
Thanks a lot!!! this is very much appreciated!!!

Haim.

>-----Original Message-----
>Hi Haim,
[quoted text clipped - 80 lines]
>>>
>.
Jakob Christensen - 28 Sep 2004 10:13 GMT
BTW, RaiseEvents can not be used to raise events declared in other modules.  
As the docs state: "You cannot use RaiseEvent to raise events that are not
explicitly declared in the module".  Reflection will work or you can inherit
from the specific class and call the protected OnXxx method (if present) of
the event.

Regards, Jakob.

> Reflection is a great idea! don't know how I didn't think
> about it myself :-)
[quoted text clipped - 95 lines]
> >>>
> >.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.