[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 285
  • Last Modified:

Raiseevent in a form in usercontrol

hey there.

I have a MDI form wi th toolbar. then, forms (MDI childs) that load usercontrols. few of those usercontrols may have internal forms. I want the toolbar buttons to relate to events occur in the usercontrols' forms. so where is the problem?

I declared public event in the usercontrol. but since the event itself occur in one of the usercontrol's form,  I can't raise the event.  as far as i know, I don't have access from forms to the usercontrol's variables and such. how do I that?
0
avi666
Asked:
avi666
  • 3
  • 3
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
you have to catch, in the usercontrol, a internal event of the form, from where you then can raise the usercontrol's event.
or, give the usercontrol a FRIEND sub that can raise the event, and pass the usercontrol object reference to the form so it can call that sub
If you need furhter explanations, don't hesitate to ask
0
 
avi666Author Commented:
hey angelIII. 10x  very much for your suggestion.
I won't hesitate to ask further explanation :)

I have a save button in the MDI toolbar and want to save changes made in the internal form of the usercontrol.

so in the MDI form i have the code:

sub toolbar_click(...)
     MDIchild.mycontrol.LogSave
end sub

in the usercontrol I have:
Public Sub LogSave()
     Call frm.SaveForm
Exit Sub

and in the frm:
Public Sub SaveForm()
...
end sub

so far, so good. the prob is that the save button is initially disabled and i want to enable it whenever a txt_change event occur in the usercontrol's form. so i added:
 
private sub mycontrol_SaveEvent
   MDImain.toolbar(SaveButton).enabled=true
end sub

and in the usercontrol declaration section:

public event SaveLog

and now I need to complete the circle with the raiseevent somewhere in some of the form's txt_change events.
how I do that with friend sub?

10x in advance.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
--- internal form code ---

private ocxToolbar as control

Public Sub InitToolbar ( c as control )
  set ocxToolbar = c
End Sub

Private Sub Withevents txt_change( ... )
  c.RaiseMyEvent ( ... )
End Sub

--- toolbar control ---

public event SaveLog

private gfrmInternalform as frmInternalform

Private Sub Class_Initialize ()
  set gfrmInternalForm = new frmInternalform
  gfrmInternalForm.initToolbar me
end sub

Friend Sub RaiseMyEvent (...)
  Raisevent SaveLog
End Sub

This should do it...
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
avi666Author Commented:
few questions.

what is "--- toolbar control ---"? where should I place the code beneth it?
in the usercontrol?

what do I do with ocxToolbar after assigning it with c?
do I need to add class module for it? (Class_Initialize )
if so, who's "Me" in that sub?

also, what is Private Sub Withevents? the compiler bugs me with this declaration...

I'm  a bit clueless...
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
>--- toolbar control ---
should actually read

--- your usercontrol ---


withevents was too much there:
Private Sub txt_change( ... )
  c.RaiseMyEvent ( ... )
End Sub

>gfrmInternalForm.initToolbar me
the ME refers to the usercontrol itself
0
 
avi666Author Commented:
well, I guess those ideas were good in their ways. I decided to stop messing with it and save the internal form directly from the form.

how easy is that? :)

take the points as a thank for your efforts.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now