Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Control Problem

Control Problem

Scheduled Pinned Locked Moved C#
helpquestion
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BLaZiNiX
    wrote on last edited by
    #1

    I created a custom control derived from a panel in which I added flat buttons but how can I add action on the buttons dynamicly ??? I can't because the class is derived from a panel. Anybody can help me ?

    N J 2 Replies Last reply
    0
    • B BLaZiNiX

      I created a custom control derived from a panel in which I added flat buttons but how can I add action on the buttons dynamicly ??? I can't because the class is derived from a panel. Anybody can help me ?

      N Offline
      N Offline
      Neil Van Note
      wrote on last edited by
      #2

      You could expose your buttons via a property as a collection (of buttons). But then you are exposing everything about the buttons.

      N 1 Reply Last reply
      0
      • B BLaZiNiX

        I created a custom control derived from a panel in which I added flat buttons but how can I add action on the buttons dynamicly ??? I can't because the class is derived from a panel. Anybody can help me ?

        J Offline
        J Offline
        James T Johnson
        wrote on last edited by
        #3

        You can expose event properties on your control; like so...

        public EventHandler ButtonA_Click
        {
        add
        {
        buttona.Click += new EventHandler(value);
        }
        remove
        {
        buttona.Click -= new EventHandler(value);
        }
        }

        You wind up with having to name the events something different, but you can control what events are available. HTH, James Simplicity Rules!

        B 1 Reply Last reply
        0
        • N Neil Van Note

          You could expose your buttons via a property as a collection (of buttons). But then you are exposing everything about the buttons.

          N Offline
          N Offline
          Neil Van Note
          wrote on last edited by
          #4

          Doh! Then again, there is nothing stopping you from accessing the built-in Controls collection of the Panel and attaching an event handler dynamically.

          1 Reply Last reply
          0
          • J James T Johnson

            You can expose event properties on your control; like so...

            public EventHandler ButtonA_Click
            {
            add
            {
            buttona.Click += new EventHandler(value);
            }
            remove
            {
            buttona.Click -= new EventHandler(value);
            }
            }

            You wind up with having to name the events something different, but you can control what events are available. HTH, James Simplicity Rules!

            B Offline
            B Offline
            BLaZiNiX
            wrote on last edited by
            #5

            The problem is that I create only one instance of a button and Each I wrote tb.AddItem("Test",Color.Black,Color.White,0); (that's an example) the control add a button itself to the parent control which is a panel. so how can I handle all the buttons actions when I have only one Button Instance ?? can I make a function like ItemClick(int index,EventHandler action) ?? if yes can u plz give me some code because I try to use this with a switch statement and I got an error : "a value constant is expected" Thanks

            J 1 Reply Last reply
            0
            • B BLaZiNiX

              The problem is that I create only one instance of a button and Each I wrote tb.AddItem("Test",Color.Black,Color.White,0); (that's an example) the control add a button itself to the parent control which is a panel. so how can I handle all the buttons actions when I have only one Button Instance ?? can I make a function like ItemClick(int index,EventHandler action) ?? if yes can u plz give me some code because I try to use this with a switch statement and I got an error : "a value constant is expected" Thanks

              J Offline
              J Offline
              James T Johnson
              wrote on last edited by
              #6

              I'm having a hard time making out what you are trying to do so let me know if what I suggest answers a different problem. What I think you're having a problem with is you only have one real button, but you have multiple click events that need to fire. Using the event handler I described above works fine; it properly handles firing of chained events (multiple methods to run when one event fires). I'm unsure what your ItemClick function is meant to do though; can you describe in words or psuedo-code what it would do? James Simplicity Rules!

              B 1 Reply Last reply
              0
              • J James T Johnson

                I'm having a hard time making out what you are trying to do so let me know if what I suggest answers a different problem. What I think you're having a problem with is you only have one real button, but you have multiple click events that need to fire. Using the event handler I described above works fine; it properly handles firing of chained events (multiple methods to run when one event fires). I'm unsure what your ItemClick function is meant to do though; can you describe in words or psuedo-code what it would do? James Simplicity Rules!

                B Offline
                B Offline
                BLaZiNiX
                wrote on last edited by
                #7

                I found it, I just added Envet Handler to my AddItem declaration :)

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups