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. Customizing buttons

Customizing buttons

Scheduled Pinned Locked Moved C#
csharptutorialquestion
3 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.
  • R Offline
    R Offline
    rul303
    wrote on last edited by
    #1

    Hi, This may be a trivial question, but I'm a newbie to GUI's and c#. I would like to use the functionality of radiobuttons but they should look like normal buttons. More specifically I want a number of buttons where only one of them is clicked active at a time. Somehow the active button should look like it's pushed down. I could use normal radio buttons but I their layout does not fit into my application and I think normal buttons (with a Text field on them) can be presented more compactly. Any suggestions on how to approach this in greatly appreaciated.

    A H 2 Replies Last reply
    0
    • R rul303

      Hi, This may be a trivial question, but I'm a newbie to GUI's and c#. I would like to use the functionality of radiobuttons but they should look like normal buttons. More specifically I want a number of buttons where only one of them is clicked active at a time. Somehow the active button should look like it's pushed down. I could use normal radio buttons but I their layout does not fit into my application and I think normal buttons (with a Text field on them) can be presented more compactly. Any suggestions on how to approach this in greatly appreaciated.

      A Offline
      A Offline
      A Wegierski
      wrote on last edited by
      #2

      Use simply labels and change their borders after click on them (create Your own inherited "RadioLabel" control). May be, You can use another control instead all "radiolabels" ... combobox etc. Hi, AW

      1 Reply Last reply
      0
      • R rul303

        Hi, This may be a trivial question, but I'm a newbie to GUI's and c#. I would like to use the functionality of radiobuttons but they should look like normal buttons. More specifically I want a number of buttons where only one of them is clicked active at a time. Somehow the active button should look like it's pushed down. I could use normal radio buttons but I their layout does not fit into my application and I think normal buttons (with a Text field on them) can be presented more compactly. Any suggestions on how to approach this in greatly appreaciated.

        H Offline
        H Offline
        Heath Stewart
        wrote on last edited by
        #3

        On top of what A.Wegierski said above, you could get the effect of having only one selected by adding a property, say Group that is a string or a collection object. If it's a string, and when one of these controls is clicked, enumerate the Parent.Controls property like so:

        protected override OnClick(EventArgs e)
        {
        if (this.Parent == null) return;
        foreach (Control c in this.Parent.Controls)
        if (c is RadioLabel && ((RadioLabel)c).Group == this.Group)
        // Easy-to-property like RadioButtons have, and also draws or remove
        // the border like A.Wegierski mentioned (if you did it that way).
        ((RadioLabel)c).Selected = c == this;
        }

        If you used a collection object (tip, implement IComponent as well to use it easily in the designer (or create a nifty designer to do this)), the object could add itself to the collection when the collection was assigned. When clicked, you run a similar routine as above but you don't have to worry about getting the parent's Controls collection or checking the group name - your collection already has the right controls:

        public GroupCollection Group
        {
        get { return this.group; }
        set
        {
        // Remove this control from the group, even if null is assigned
        // (easy way to remove a RadioLabel (or whatever) from its group).
        if (this.group != null) this.group.Remove(this);
        // Assign the group and, if not null, add this control to it.
        this.group = value;
        if (this.group != null) this.group.Add(this);
        }
        }

        -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

        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