Complex UserControl, need help...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • junk

    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.




  • Ciaran O''Donnell

    #2
    RE: Complex UserControl, need help...

    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 RadioButtonArra yClickHandler(R adioButtonArray sender,
    EventArgs e);
    public event RadioButtonArra yClickHandler 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.
    >
    >
    >
    >
    >

    Comment

    • Dave Sexton

      #3
      Re: Complex UserControl, need help...

      Hi Ciaran,

      Note: the standard naming convention would be:

      protected virtual void OnClick(EventAr gs e)
      {
      }

      and could be invoked from the UserControl as such:

      OnClick(EventAr gs.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<Ra dioClickEventAr gsClick;

      public class RadioClickEvent Args : EventArgs
      {
      ...
      }

      --
      Dave Sexton

      "Ciaran O''Donnell" <CiaranODonnell @discussions.mi crosoft.comwrot e in
      message news:D4B106F5-BB16-4B01-82AF-8D8A5123887F@mi crosoft.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 RadioButtonArra yClickHandler(R adioButtonArray sender,
      EventArgs e);
      public event RadioButtonArra yClickHandler 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.
      >>
      >>
      >>
      >>
      >>

      Comment

      • junk

        #4
        Re: Complex UserControl, need help...

        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.



        Comment

        • Jeff Louie

          #5
          Re: Complex UserControl, need help...

          junk... This may help

          Latest news coverage, email, free stock quotes, live scores and video are just the beginning. Discover more every day at Yahoo!


          Regards,
          Jeff

          *** Sent via Developersdex http://www.developersdex.com ***

          Comment

          • junk

            #6
            Re: Complex UserControl, need help...

            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 OnClickEventHan dler(object sender, EventArgs e);
            public event OnClickEventHan dler Click;

            protected virtual void OnClick(EventAr gs 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.


            Comment

            • Dave Sexton

              #7
              Re: Complex UserControl, need help...

              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 OnClickEventHan dler(object sender, EventArgs e);
              public event OnClickEventHan dler Click;
              >
              protected virtual void OnClick(EventAr gs 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.EventHan dler.

              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


              Comment

              Working...