Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / November 2006

Tip: Looking for answers? Try searching our database.

Complex UserControl, need help...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
junk - 17 Nov 2006 15:51 GMT
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.
Ciaran O''Donnell - 17 Nov 2006 16:07 GMT
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

> Senerio:
> I have a custom user control which contains two control arrays. The user
[quoted text clipped - 19 lines]
>
> Thanks - Johan.
Dave Sexton - 17 Nov 2006 16:18 GMT
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<RadioClickEventArgs> Click;

public class RadioClickEventArgs : EventArgs
{
   ...
}

Signature

Dave Sexton

> 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
[quoted text clipped - 37 lines]
>>
>> Thanks - Johan.
junk - 17 Nov 2006 18:04 GMT
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.
Dave Sexton - 17 Nov 2006 18:46 GMT
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;
[quoted text clipped - 8 lines]
> 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 ;)

Signature

Dave Sexton

junk - 17 Nov 2006 16:39 GMT
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.
Jeff Louie - 17 Nov 2006 16:53 GMT
junk... This may help

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

Regards,
Jeff

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.