VB2005: Can a usercontrol 'trigger' your main form ?

  • Thread starter Thread starter Screaming Eagles 101
  • Start date Start date
S

Screaming Eagles 101

Hi,

I have a solution containing two projects
- main project with main form containing a statusstrip
- second project containing a usercontrol.

I have added the usercontrol to my main form, all works perfect...

Can my usercontrol 'fire an event' which allows it to change the value(s) on
the main form's statusstrip ?

--
Filip
http://www.ww2airborne.net/
Official Site of the 101st Airborne - 463rd PFA
skype: airborne463pfa-fiwi
[It's nice to be important, but it's more important to be nice!]
----------------------------------------------------------------
 
Spam Catcher said:
Yup. Provided your main form hooks into the event.

Thanks, that's promessing,
unfortunately I'm not smart enough to find out how, the reason for my
question here...
Does one have the knowledge how to perform this ?
--
Filip
http://www.ww2airborne.net/
Official Site of the 101st Airborne - 463rd PFA
skype: airborne463pfa-fiwi
[It's nice to be important, but it's more important to be nice!]
----------------------------------------------------------------
 
Armin Zingler said:

Thanks, digging around in the code I was able to make the examples
work, etc.. but only if I stay in the usercontrol project completely,
or if I stay in the main form project completely.
I don't get it how I can raise an event in my usercontrol project
and pick it up in my main form project to change the text of the statustrip.

Solution myVB2005Solution
+ Project Main
--- frmMain <= change the te text on the statusstrip (or textbox,
whatever), contains an instance of myUserControl
--- frmSplash
--- some modules...
+ Project Mycontrols
--- myUserControl => send a 'trigger' to frmMain to change the text
property of a certain control
 
Screaming Eagles 101 said:
Thanks, digging around in the code I was able to make the examples
work, etc.. but only if I stay in the usercontrol project
completely, or if I stay in the main form project completely.
I don't get it how I can raise an event in my usercontrol project
and pick it up in my main form project to change the text of the
statustrip.

Solution myVB2005Solution
+ Project Main
--- frmMain <= change the te text on the statusstrip (or
textbox, whatever), contains an instance of myUserControl
--- frmSplash
--- some modules...
+ Project Mycontrols
--- myUserControl => send a 'trigger' to frmMain to change the
text property of a certain control

You added "Public event xy" to the Usercontrol?
You added "Raiseevent xy" to the Usercontrol?
In the "Main" project, in the code editor for frmMain, you can not select
the event in the top-right combo after selecting the Usercontrol in the
top-left combo?


Armin
 
Screaming Eagles 101 said:
Thanks, digging around in the code I was able to make the examples
work, etc.. but only if I stay in the usercontrol project completely,
or if I stay in the main form project completely.
I don't get it how I can raise an event in my usercontrol project
and pick it up in my main form project to change the text of the
statustrip.

Solution myVB2005Solution
+ Project Main
--- frmMain <= change the te text on the statusstrip (or textbox,
whatever), contains an instance of myUserControl
--- frmSplash
--- some modules...
+ Project Mycontrols
--- myUserControl => send a 'trigger' to frmMain to change the text
property of a certain control

OK I got it working, thanks for your help. I found what I need.... :-)

* ON THE USER CONTROL:
Public Event myEvent(ByVal s As String)

Private Sub btnReportPrint_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnReportPrint.Click
RaiseEvent myEvent("Fire!")
End Sub

* ON FRMMAIN

Public Sub FireEvent(ByVal s As String) Handles InfoControl1.myEvent
Me.Text = s & ": okay, I am on frmMain !!!!!"
End Sub
 
Screaming Eagles,

You can even get it direct by casting it to the parentform of the
usercontrol.

Cor
 
Cor Ligthert said:
Screaming Eagles,

You can even get it direct by casting it to the parentform of the
usercontrol.

The question was how to raise and catch an event. In addition, casting to
the parent form type doesn't make the UserControl reusable.


Armin
 
The question was how to raise and catch an event. In addition, casting to
the parent form type doesn't make the UserControl reusable.

Strange I read something else, even in the subject.

Something wrong with my newsreader?

Cor
 
Cor Ligthert said:
Strange I read something else, even in the subject.

Something wrong with my newsreader?

I read "Can my usercontrol 'fire an event' ... ?"


Armin
 
I read "Can my usercontrol 'fire an event' ... ?"
There is more Armin, Beside what is before that, is the full sentence you
are refering to. "Can my usercontrol 'fire an event' which allows it to
change the value(s) on the main form's statusstrip ?

Therefore my answer, "You can even get it direct by casting it to the
parentform of the
usercontrol".

I can tell you from own expirience that it is much easier to change the
value(s) on the main form.

Cor
 
Armin Zingler said:
I read "Can my usercontrol 'fire an event' ... ?"


Armin

Dear readers,
the subject could be confusing.
The goal was to raise an event in the usercontrol, which the main form could
trigger.
In this case I have an event on the usercontrol, when raised I want the main
form
to pick it up and show a message on the statusstrip.
I was able to do this which I explained in an earlier post here in this
topic/message.
Thanks for your help.
--
Filip
http://www.ww2airborne.net/
Official Site of the 101st Airborne - 463rd PFA
skype: airborne463pfa-fiwi
[It's nice to be important, but it's more important to be nice!]
----------------------------------------------------------------
 
Cor Ligthert said:
Screaming Eagles,

You can even get it direct by casting it to the parentform of the
usercontrol.

Cor


Cor, and other readers,

I also found out that it is a nice working solution to
add all my Events to a Class,
and declare them SHARED (very important).

In the same class I have the subroutines
which perform the RaiseEvent for each Event.

Once I instantiated the class - withEvents -
on my forms I have instant access to the shared events.

Works like a charm !

--
Filip
http://www.ww2airborne.net/
Official Site of the 101st Airborne - 463rd PFA
skype: airborne463pfa-fiwi
[It's nice to be important, but it's more important to be nice!]
----------------------------------------------------------------
 
Back
Top