Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
UserControl
Message
General information
Forum:
ASP.NET
Category:
Other
Title:
Miscellaneous
Thread ID:
00714741
Message ID:
00716671
Views:
12
This is really a design issue. To create a User Control that can be generic for multiple forms, simply create an interface and impliment it on each form that will use the User Control. Then when calling the method on the form inside of the User Control, cast to the interface. The interface method would then call the method on the form you want to fire.
CType(Me.FindForm(), MyInterface).MyMethod()
>Cathi, it does not work I can't see my form because it's in a deferant application in the same solution.
>I stop here:
>CType(me.FindForm(), Windows.Forms.Form.
>after Form. it shows only these options (DockPaddingEdgesConverter(), DockPaddingEdges(), ControlCollection())
>
>By the way, is what I am dowin is correct, I am writing these click_event handelar in the user control xx button click area ?
>
>ADSC
>
>
>>Try using:
>>
>>
>>CType(Me.FindForm(), Windows.Forms.Form.ActiveForm.ActiveMdiChild).MyButton.PerformClick()
>>
>>
>>This will get a reference to the actual form to cast to.
>>
>>>Hi Cathi,
>>>
>>>“CType(Me.FindForm(), MyForm).MyButton.PerformClick()”
>>>It’s not working, MyForm is a string memory variable having the form name
>>>
>>>What I am doing is saving the my user controlled “Buttons” in another project “Windows Control Library” type and in my original exe application adding the user control to my form.
>>>
>>>Now from the user control project I am butting some controls on every button event click, and in side I have to know this click is coming from which form by doing this:
>>>“ strFormName = Windows.Forms.Form.ActiveForm.ActiveMdiChild.Name “
>>>then I need to call a seatrain procedure in the exe application which holding the original form.
>>>
>>>The scope is, making my user control in a separate project “Windows Control Library” and call these user control buttons from any application.
>>>
>>>Thank you for your help and your time.
>>>
>>>ADSC
>>>
>>>
>>>
>>>
>>>>To call a method on your form that hosts the UserControl, you use the FindForm method of the UserControl. You need to cast the Form to the specific class of the form that is hosting the control. In the control inside the UserControl you reference a method on the form like:
>>>>
>>>>
>>>>CType(Me.FindForm(), MyForm).MyButton.PerformClick()
>>>>
>>>>
>>>>>Hi Cathi,
>>>>>
>>>>>Fist, I would like to thank you for your excellent help, you always give me your assistant.
>>>>>
>>>>>Cathi, What I need is the oposit way ... the user control "uc_Buttos" have 5 buttons in the form, when the user clicks on btnAdd for example I should berform the add procedure .. that I need to know how to do this, because when I click in the button the event in the user control event is excuted .. so how to link it to the form I am using now??
>>>>>
>>>>>What I am trying now, I found a way which is:
>>>>>In the user control click_event I track which form is active, get the form name by doing this command :
>>>>>"strFormName = Windows.Forms.Form.ActiveForm.ActiveMdiChild.Name"
>>>>>then inhiret a new form from the called form:
>>>>>"Dim j As New Windows.Forms.Form(strFormName)"
>>>>>then excute the add procedure in the origenal form:
>>>>>j.AddRecord()
>>>>>
>>>>>this way is working if I am passing the original form name, but when I pass the variable it's not working.
>>>>>
>>>>>Maybe my way is wrong ... and maybe it's correct but need a litle modifications.
>>>>>
>>>>>Please advice
>>>>>
>>>>>Many thanks to you
>>>>>
>>>>>ADSC
>>>>>
>>>>>>To call the click event from a button inside a user control, you would do the following:
>>>>>>
>>>>>>
>>>>>>Me.UserControl11.Button1.PerformClick()
>>>>>>
>>>>>>
>>>>>>>Hi all,
>>>>>>>
>>>>>>>I am trying to move my standard buttons like “Add, Save, Delete, Exit” to a “User Control”, then I add this user control to my application forms.
>>>>>>>
>>>>>>>The problem, I don’t know how to control the click event for each button on the form because in the form I see the user control as one part.
>>>>>>>
>>>>>>>Can anyone help me in doing this.
>>>>>>>
>>>>>>>Appreciate any assistance
>>>>>>>
>>>>>>>ADSC
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Previous
Reply
Map
View

Click here to load this message in the networking platform