473,503 Members | 1,635 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Complex UserControl, need help...

Senerio:
I have a custom user control which contains two control arrays. The user
control has a group box in which the two control arrays are dynamically
built. The two control arrays are RadioButtons and PictureBoxes.

Task:
What I need to accomplish with this custom user control is to rearrange the
pictures in the PictureBox Control Array based on what RadioButton is
selected. I do not want my RadioButton Control array to have a dependency on
the PictureBox Control Array as I use that RadioButton Control array
elsewhere in this project.

My though is that I need to have an "event monitor" in the custom user
control, such that when the RadioButton OnClick event is fired the parent is
notified and can then fire off a method to handle changing the pictures in
the PictureBox array. This is however, something that I have not tackled in
the passed so I am unsure how to approach getting this accomplished. There
is most likely a very easy solution.

If anyone would be so kind as to point me into the right direction I would
be very grateful...

Thanks - Johan.


Nov 17 '06 #1
6 2657
Add the below to your class and whenever you radio buttons are clicked you
can call RaiseClick() which will raise the Click event if anybody is
subscribed. Then your form can handle click like it does with a button.
public delegate void RadioButtonArrayClickHandler(RadioButtonArray sender,
EventArgs e);
public event RadioButtonArrayClickHandler Click;

protected void RaiseClick(){
if (Click != null)Click(this,new EventArgs());
}

HTH

Ciaran O'Donnell

"junk" wrote:
Senerio:
I have a custom user control which contains two control arrays. The user
control has a group box in which the two control arrays are dynamically
built. The two control arrays are RadioButtons and PictureBoxes.

Task:
What I need to accomplish with this custom user control is to rearrange the
pictures in the PictureBox Control Array based on what RadioButton is
selected. I do not want my RadioButton Control array to have a dependency on
the PictureBox Control Array as I use that RadioButton Control array
elsewhere in this project.

My though is that I need to have an "event monitor" in the custom user
control, such that when the RadioButton OnClick event is fired the parent is
notified and can then fire off a method to handle changing the pictures in
the PictureBox array. This is however, something that I have not tackled in
the passed so I am unsure how to approach getting this accomplished. There
is most likely a very easy solution.

If anyone would be so kind as to point me into the right direction I would
be very grateful...

Thanks - Johan.


Nov 17 '06 #2
Hi Ciaran,

Note: the standard naming convention would be:

protected virtual void OnClick(EventArgs e)
{
}

and could be invoked from the UserControl as such:

OnClick(EventArgs.Empty);
And in 2.0 there is no longer a need to declare a custom delegate, just a
custom EventArgs implementation when desired:

public event EventHandler<RadioClickEventArgsClick;

public class RadioClickEventArgs : EventArgs
{
...
}

--
Dave Sexton

"Ciaran O''Donnell" <Ci************@discussions.microsoft.comwrote in
message news:D4**********************************@microsof t.com...
Add the below to your class and whenever you radio buttons are clicked you
can call RaiseClick() which will raise the Click event if anybody is
subscribed. Then your form can handle click like it does with a button.
public delegate void RadioButtonArrayClickHandler(RadioButtonArray sender,
EventArgs e);
public event RadioButtonArrayClickHandler Click;

protected void RaiseClick(){
if (Click != null)Click(this,new EventArgs());
}

HTH

Ciaran O'Donnell

"junk" wrote:
>Senerio:
I have a custom user control which contains two control arrays. The user
control has a group box in which the two control arrays are dynamically
built. The two control arrays are RadioButtons and PictureBoxes.

Task:
What I need to accomplish with this custom user control is to rearrange the
pictures in the PictureBox Control Array based on what RadioButton is
selected. I do not want my RadioButton Control array to have a dependency
on
the PictureBox Control Array as I use that RadioButton Control array
elsewhere in this project.

My though is that I need to have an "event monitor" in the custom user
control, such that when the RadioButton OnClick event is fired the parent
is
notified and can then fire off a method to handle changing the pictures in
the PictureBox array. This is however, something that I have not tackled in
the passed so I am unsure how to approach getting this accomplished. There
is most likely a very easy solution.

If anyone would be so kind as to point me into the right direction I would
be very grateful...

Thanks - Johan.



Nov 17 '06 #3
Ciaran,
Thank you for the quick response. Sorry, but I must ask and so to
clearify...

Put the delegate (your example code) into the control array?

This then allows the custom user control to subscribe to the event. What
does the call in the customer user control look like?

Thanks again - Johan.

Nov 17 '06 #4
junk... This may help

http://www.geocities.com/jeff_louie/oop31.htm

Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '06 #5
Dave,

I am very confused at this point. The Event propagation from the RadioButton
Control Array to the User Control is still not intuitive enough for me to
grasp. I must be a blockhead.....

Is the following correct?

In the RadioButton Control Array I add the following:
NOTE: I assume that if I already have a ClickHandler in this control array I
should remove it?

public delegate void OnClickEventHandler(object sender, EventArgs e);
public event OnClickEventHandler Click;

protected virtual void OnClick(EventArgs e){
if (Click != null) {
// Invokes the delegates.
Click(this, e);
}
}

Now how does this notifiy my user control that a radio button was click so
that the user control can react to it?

Sorry to be such a pain...

Johan.
Nov 17 '06 #6
Hi Johan,
I am very confused at this point. The Event propagation from the RadioButton
Control Array to the User Control is still not intuitive enough for me to
grasp. I must be a blockhead.....
Maybe if you clarify this statement:

"What I need to accomplish with this custom user control is to rearrange the
pictures in the PictureBox Control Array based on what RadioButton is
selected"

then I'll probably be able to help you.
Is the following correct?

In the RadioButton Control Array I add the following:
NOTE: I assume that if I already have a ClickHandler in this control array I
should remove it?
What do you mean by, "In" the RadioButton Control Array?

I assumed that it was just a one-dimensional array of RadioButtons. Is it a
custom control? If so, is the PictureBox Control Array you have been
referring to a custom control as well?

If so, what are the exact names of the custom controls? (it will be much
easier to refer to them using their given names)
public delegate void OnClickEventHandler(object sender, EventArgs e);
public event OnClickEventHandler Click;

protected virtual void OnClick(EventArgs e){
if (Click != null) {
// Invokes the delegates.
Click(this, e);
}
}

Now how does this notifiy my user control that a radio button was click so
that the user control can react to it?
Well, you aren't using the standardized naming convention for the delegate,
but since you're only using EventArgs you don't even need to declare a
delegate anyway. You could just use System.EventHandler.

But, before answering this question I think you might want to answer mine. I
don't want to confuse the situation.
Sorry to be such a pain...
No pain, no gain - or something like that ;)

--
Dave Sexton
Nov 17 '06 #7

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

Similar topics

4
2020
by: DraguVaso | last post by:
Hi, I'm having some weird behaviour, and I can't find any solution to this. I made a UserControl (uclCommands) which contains a Toolbar (ToolBar1) with Modifiers = Public. I put this...
4
7954
by: Mark Friedman | last post by:
I can't seem to figure out how to get a reference to a UserControl in the code-behind for the page that contains the control. All the examples I've seen show how to pass property values from the...
2
1233
by: Lau Lei Cheong | last post by:
Hello, I'm writing a usercontrol that contains a property named "disabled". It is set to false by default but there is also another button in the usercontrol that'll set it to true. On the...
8
1946
by: Raed Sawalha | last post by:
Hi, I have a strange problem with a usercontrol on a page. The usercontrol dispalyes three categories (From a database) when the user clicks a category they see all the products in a shop for...
41
4237
by: JohnR | last post by:
In it's simplest form, assume that I have created a usercontrol, WSToolBarButton that contains a button. I would like to eventually create copies of WSToolBarButton dynamically at run time based...
1
2998
by: Philipp Lenz | last post by:
I'm very confused about how this works, all the tutorials out there show me how to apply a skin to a webcontrol, but I want to know how I can access the components of a control....for example: I...
12
2179
by: Joe | last post by:
Hello All: Do I have to use the LoadControl method of the Page to load a UserControl? I have a class which contains three methods (one public and two private). The class acts as a control...
9
14418
by: Marcelo Cabrera | last post by:
Hi, I have a user control that in turn creates a bunch of webcontrols dynamically and handles the events these webcontrols raise. It used to work fine on ASP .Net 1.1 but when compiled on 2.0 it...
1
3223
by: Giovanni | last post by:
Dear Friends/Gurus, I have exhausted myself and have yet no solution to the following: I have an ASP.NET 2.0 Survey type application. On a page, I have placed a GridView which is bound to an...
0
7086
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
7280
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7332
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...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
4673
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
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
382
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.