 |
| C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

July 29th, 2003, 06:37 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
|
|
run function from UserControl
How can I fire a function im my from from UserControl 
any help appreciate.
Always:),
Hovik Melkomian.
__________________
Always,
Hovik Melkomian.
|
|

July 30th, 2003, 07:54 AM
|
|
Registered User
|
|
Join Date: Jul 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
You need to create an event in your user control that will fire when you want to tell you form to fire it's function.
(This code is for a usercontrol that adds new items to a database.)
public delegate void AddEventHandler(
object sender,
EventArgs e);
public event AddEventHandler AddEvent;
protected virtual void OnAddEvent(EventArgs e)
{
if (AddEvent != null)
AddEvent(this, e);
}
Add into the usercontrol code
OnAddEvent(EventArgs.Empty);
whereever it is appropriate for this event to fire.
Once you get these set up in the usercontrol, then create an event handler in the form.
In the InitializeComponent() in designer generated code, add the event-
this.ctlAddNewRule.AddEvent += new NewRulePanel.AddEventHandler(this.OnAddNewRuleEven t);
and create the handler -
protected void OnAddNewRuleEvent(
object sender,
System.EventArgs e)
{
--whatever function code you want the form to perform--
}
|
|

July 31st, 2003, 05:45 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
|
|
Dear friend:
tnx for ur reply! but I couldn't got ur code well!
Where is my OnClick even for button in UserControl?!?
could u explain more this topic?
I'll be thankfull.
Always:),
Hovik Melkomian.
|
|

August 3rd, 2003, 03:20 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
|
|
Im still stuck in my problem  .
NO IDEA?!?!
Always:),
Hovik Melkomian.
|
|

August 5th, 2003, 07:55 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,101
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
Melvik,
I have no idea why you asked me to look at this. I have no knowledge of C#.
That said, the answer you got looks appropriate. In the VB.NET world we would just have a function that handles the event in question. Of course, the event fires as appropriate (EG: Click).
And, quite frankly I don't quite understand what your trying to find out..
Hal Levy
Unemployed (Thanks GWB)
NOT a Wiley/Wrox Employee
|
|

August 5th, 2003, 07:59 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 231
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi there Hovik, you sent me an email asking for my help. Unfortunately I am not a C# programmer so I barely understand your problem, let alone being able to provide you with a solution.
I hope that someone can help you with your code.
Quote:
quote:
To: owain
From: melvik
Subject: Sent From p2p.wrox.com Forums by melvik
Dear friend:
Can u please take a look at my problem & help me?!
This is the link http://p2p.wrox.com/topic.asp?TOPIC_ID=2336
Always, Hovik.
|
Regards
Owain Williams
|
|

August 5th, 2003, 10:07 AM
|
|
Registered User
|
|
Join Date: Jul 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Microsoft Press's Visual C#.NET Step By Step Chapter 23 deals with this topic. If you can't get access to this book, have a look at this:
http://msdn.microsoft.com/vstudio/us...formusecon.asp
Good luck.
()x.
|
|

August 5th, 2003, 10:57 AM
|
|
Registered User
|
|
Join Date: Jul 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
If the button is in the UserControl, then you can go to design and click on the button. In the properties, select the lightening bolt. If you don't already have a button_Click event, then double click on the "Click", and VS will generate the basic function code. You then just add whatever code you need. Probably assign values to the usercontrol properties. Then add the event to notify the parent that the UserControl is done and start the function in the parent.
private void myButton_Click (object sender, System.EventArgs e)
{
... your code, if any ...
OnAddEvent(EventArgs.Empty);
}
In this example, I'm not passing any data, (EventArgs.Empty) because it's in my properties, so I'm just notifying the parent to start it's function, which is
protected void OnAddNewRuleEvent(object sender, System.EventArgs e)
{
... the rest of my code ...
}
HTH, Dawn.
|
|

August 5th, 2003, 06:25 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 308
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hovic,
I'm in the same boat as Hal and Owain - I'm not a C# programmer - I did one subject at uni in C++ years ago, but that's about as close as I get.
Having said that - it looks like Dawn has solved your problem.
Steven
I am a loud man with a very large hat. This means I am in charge
|
|

August 5th, 2003, 06:37 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 215
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I don't write C#. If I did I'd also subscribe to the C# forum and I'd be asking questions or suggesting answers.
regards
David Cameron
|
|
 |