473,473 Members | 1,581 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Passing Events from a user control to a form using the user control

I have a quick question on custom controls.

I have a control that I created with a class that extends the
NumericUpDown control.

My problem is that when I use this usercontrol on my form, the click
event gets handled by the user class. I want the event to be passed to
the Windows form (not the user control).

So I am guessing that I need to raise an event from the user control
click event

User Control Click -Gets handled by the user control method:
private void NumericUpDownControl_Click(object sender, EventArgs e)
{
// Raise an event that I can process on the calling form??
// In other words, I need the click event on the user
control to trigger a method on
// the Windows Form that is using the control.
}

Does this make sense?
Am I on the right track here? Please bear with me as this is my first
attempt at a custom control.

Thanks!
-Guy

Oct 2 '06 #1
5 1821

Guy Noir wrote:
I have a quick question on custom controls.

I have a control that I created with a class that extends the
NumericUpDown control.

My problem is that when I use this usercontrol on my form, the click
event gets handled by the user class. I want the event to be passed to
the Windows form (not the user control).

So I am guessing that I need to raise an event from the user control
click event

User Control Click -Gets handled by the user control method:
private void NumericUpDownControl_Click(object sender, EventArgs e)
{
// Raise an event that I can process on the calling form??
// In other words, I need the click event on the user
control to trigger a method on
// the Windows Form that is using the control.
}

Does this make sense?
Am I on the right track here? Please bear with me as this is my first
attempt at a custom control.
Yes, you are on exactly the right track. The only thing that you need
to clarify is what message you're attempting to transmit to the
enclosing form. In other words, what does this use click mean in
higher-level terms? Why does the enclosing form want to know? If you
know that then you'll know exactly when to raise the event and what to
name it.

Oct 2 '06 #2

Guy Noir wrote:
I have a quick question on custom controls.

I have a control that I created with a class that extends the
NumericUpDown control.

My problem is that when I use this usercontrol on my form, the click
event gets handled by the user class. I want the event to be passed to
the Windows form (not the user control).

So I am guessing that I need to raise an event from the user control
click event

User Control Click -Gets handled by the user control method:
private void NumericUpDownControl_Click(object sender, EventArgs e)
{
// Raise an event that I can process on the calling form??
// In other words, I need the click event on the user
control to trigger a method on
// the Windows Form that is using the control.
}

Does this make sense?
Am I on the right track here? Please bear with me as this is my first
attempt at a custom control.
Yes, you are on exactly the right track. The only thing that you need
to clarify is what message you're attempting to transmit to the
enclosing form. In other words, what does this use click mean in
higher-level terms? Why does the enclosing form want to know? If you
know that then you'll know exactly when to raise the event and what to
name it.

Oct 2 '06 #3
Thanks for the reply Bruce.

What I want to know exactly is when the control is clicked. When this
control is clicked, I want to update a text field in the form with the
value of the user control.

Thanks!
-Guy
Bruce Wood wrote:
Guy Noir wrote:
I have a quick question on custom controls.

I have a control that I created with a class that extends the
NumericUpDown control.

My problem is that when I use this usercontrol on my form, the click
event gets handled by the user class. I want the event to be passed to
the Windows form (not the user control).

So I am guessing that I need to raise an event from the user control
click event

User Control Click -Gets handled by the user control method:
private void NumericUpDownControl_Click(object sender, EventArgs e)
{
// Raise an event that I can process on the calling form??
// In other words, I need the click event on the user
control to trigger a method on
// the Windows Form that is using the control.
}

Does this make sense?
Am I on the right track here? Please bear with me as this is my first
attempt at a custom control.

Yes, you are on exactly the right track. The only thing that you need
to clarify is what message you're attempting to transmit to the
enclosing form. In other words, what does this use click mean in
higher-level terms? Why does the enclosing form want to know? If you
know that then you'll know exactly when to raise the event and what to
name it.
Oct 2 '06 #4
It sounds to me as though you want to know when the control's value has
changed, not whenever it is clicked. That's why I asked: I wasn't
convinced that it wasn't a Click that you were after, but something
else.

So, maybe you want something like:

public event System.EventHandler ValueChanged;

private void NumericUpDownControl_ValueChanged(object sender,
System.EventArgs e)
{
if (this.ValueChanged != null)
{
this.ValueChanged(this, System.EventArgs.Empty);
}
}

which assumes, of course, that your user control exposes a
corresponding Value property....

Guy Noir wrote:
Thanks for the reply Bruce.

What I want to know exactly is when the control is clicked. When this
control is clicked, I want to update a text field in the form with the
value of the user control.

Thanks!
-Guy
Bruce Wood wrote:
Guy Noir wrote:
I have a quick question on custom controls.
>
I have a control that I created with a class that extends the
NumericUpDown control.
>
My problem is that when I use this usercontrol on my form, the click
event gets handled by the user class. I want the event to be passed to
the Windows form (not the user control).
>
So I am guessing that I need to raise an event from the user control
click event
>
User Control Click -Gets handled by the user control method:
private void NumericUpDownControl_Click(object sender, EventArgs e)
{
// Raise an event that I can process on the calling form??
// In other words, I need the click event on the user
control to trigger a method on
// the Windows Form that is using the control.
}
>
Does this make sense?
Am I on the right track here? Please bear with me as this is my first
attempt at a custom control.
Yes, you are on exactly the right track. The only thing that you need
to clarify is what message you're attempting to transmit to the
enclosing form. In other words, what does this use click mean in
higher-level terms? Why does the enclosing form want to know? If you
know that then you'll know exactly when to raise the event and what to
name it.
Oct 2 '06 #5
Bruce, worked like a charm!

Thanks so much for your valuable input!!

-Guy

Bruce Wood wrote:
It sounds to me as though you want to know when the control's value has
changed, not whenever it is clicked. That's why I asked: I wasn't
convinced that it wasn't a Click that you were after, but something
else.

So, maybe you want something like:

public event System.EventHandler ValueChanged;

private void NumericUpDownControl_ValueChanged(object sender,
System.EventArgs e)
{
if (this.ValueChanged != null)
{
this.ValueChanged(this, System.EventArgs.Empty);
}
}

which assumes, of course, that your user control exposes a
corresponding Value property....

Guy Noir wrote:
Thanks for the reply Bruce.

What I want to know exactly is when the control is clicked. When this
control is clicked, I want to update a text field in the form with the
value of the user control.

Thanks!
-Guy
Bruce Wood wrote:
Guy Noir wrote:
I have a quick question on custom controls.

I have a control that I created with a class that extends the
NumericUpDown control.

My problem is that when I use this usercontrol on my form, the click
event gets handled by the user class. I want the event to be passed to
the Windows form (not the user control).

So I am guessing that I need to raise an event from the user control
click event

User Control Click -Gets handled by the user control method:
private void NumericUpDownControl_Click(object sender, EventArgs e)
{
// Raise an event that I can process on the calling form??
// In other words, I need the click event on the user
control to trigger a method on
// the Windows Form that is using the control.
}

Does this make sense?
Am I on the right track here? Please bear with me as this is my first
attempt at a custom control.
>
Yes, you are on exactly the right track. The only thing that you need
to clarify is what message you're attempting to transmit to the
enclosing form. In other words, what does this use click mean in
higher-level terms? Why does the enclosing form want to know? If you
know that then you'll know exactly when to raise the event and what to
name it.
Oct 3 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Andy | last post by:
Hi everyone, Small problem we are having here, just wanted to see if anyone could help out. Basically we have a user control with a textbox (that is docked to fill the whole control) that is...
1
by: Souri Challa | last post by:
Hi all, Is there any way to pass a large amount of data from an asp.net form to another browser window opened through client script ? (i.e without using sessions ). Here is my scenario.I've a...
4
by: thomson | last post by:
Hi all, i do have a user control with 4 buttons, and all the events are firing properly, My problem is that i need to right an event handler in the user control, which gets fired after a...
12
by: scsharma | last post by:
Hi, I am working on creating a webapplication and my design calls for creating main webform which will have menu bar on left hand side and a IFrame which will contain all the forms that are shown...
0
by: Scott McChesney | last post by:
I have a problem I hope you folks can help me with. I have an application that is using a tab-based interface, with the ability for users to drag an item from a ListBox onto the tab control. ...
7
by: Jason | last post by:
Hello I've got a very simple C# app, that has a datagrid, a text box, and a button which when clicked opens a second form... Form2 frm2 = new Form2(); frm2.Show(); When I place a datagrid,...
1
by: Dave A | last post by:
I have a problem that I have boiled down to a very simple example. I have a user control that displays a some data from a business object. On one screen I have a collection of these business...
2
by: shark | last post by:
hi, I have user control placed on form. How to make this control transparent for mouse events. I need to handle mouse events in form not in user control (like label ctrl). Thanks Shark
1
by: brixdotnet | last post by:
Hi there! I made own user control for displaying and editing content. In Page_Load of this control is checked if user is authorized for editing if so, button for editing is shown, otherwise...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.