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