Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Raiseevent in a form in usercontrol

Posted on 2006-07-10
6
277 Views
Last Modified: 2013-12-25
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
Comment
Question by:avi666
  • 3
  • 3
6 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17071900
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
 

Author Comment

by:avi666
ID: 17072961
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
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 125 total points
ID: 17074502
--- 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:avi666
ID: 17079173
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
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17079205
>--- 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
 

Author Comment

by:avi666
ID: 17145355
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question