Solved

Raiseevent in a form in usercontrol

Posted on 2006-07-10
6
269 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 142

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 142

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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

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 142

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now