473,401 Members | 2,139 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

how do you make a button stay depressed

take away its prozac ?
no seriously
I want to drop a button onto a form, then during runtime, when user
clicks the button it stays in the "depressed" image state (with a new
color) then when it is pressed again it pops up to its normal state
and color
and of course i want to execute code on each push down and pop up

any idea how this can be done please.
Also a way to make an array of such depresseable buttons, that
function like an array of radio buttons in that only 1 on the panel is
ever selected at any one time
thanks for any advice

Peted
Feb 23 '07 #1
2 16835
One way os to use the ControlPaint class and draw the button yourself.

public class ToggleButton : Button
{
public ToggleButton()
{
SetStyle(ControlStyles.UserPaint, true);
}
protected override void OnPaint(PaintEventArgs pevent)
{
// base.OnPaint(pevent);
ControlPaint.DrawButton(pevent.Graphics,
this.ClientRectangle, toggleState);
using (Brush b = new SolidBrush(ForeColor))
{
SizeF sz = pevent.Graphics.MeasureString(Text, Font);
float x = Math.Max(2, (ClientSize.Width - sz.Width) /
2);
float y = Math.Max(2, (ClientSize.Height -
sz.Height) / 2);
pevent.Graphics.DrawString(Text, Font, b, x, y); //
draw the text on the button
}
}
protected override void OnClick(EventArgs e)
{
base.OnClick(e);
toggleState = toggleState == ButtonState.Normal ?
ButtonState.Pushed : ButtonState.Normal;
this.Invalidate();
}
ButtonState toggleState = ButtonState.Normal;
}
===================
Clay Burch
Syncfusion, Inc.

Feb 23 '07 #2
Peted wrote:
take away its prozac ?

no seriously

I want to drop a button onto a form, then during runtime, when user
clicks the button it stays in the "depressed" image state (with a new
color) then when it is pressed again it pops up to its normal state
and color

and of course i want to execute code on each push down and pop up

any idea how this can be done please.
This seems like check box functionality. Why not to use checkbox
instead with its Appearance property set to Button?
Also a way to make an array of such depresseable buttons, that
function like an array of radio buttons in that only 1 on the panel is
ever selected at any one time
Same thing: radio button has Appearance property which can be set to
Button making it look like push button.
Feb 23 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Dan V. | last post by:
I am looking for a great css button navigation tool that can allow me to: - Ideally use Macromedia DreamWeaver 2004 mx. - Use CSS buttons that allows the button to stay depressed when I am on a...
3
by: Jozef | last post by:
Hi Folks! I'm wondering if there is a way to make an access button appear pressed in? I know there was a property or something similar in VB to make a button appear pressed in. What I'm...
2
by: John | last post by:
Hi How can I create a toggle button on a toolbar that would enable/disable editing on the current form? Thanks Regards
18
by: jrhoads23 | last post by:
Hello, I am trying to find a way to tell if an .NET windows forms Button (System.Windows.Forms.Button) is "depressed" (pushed down). For my application, I can not use a check box control set to...
18
by: Colin McGuire | last post by:
Hi - this was posted last weekend and unfortunately not resolved. The solutions that were posted almost worked but after another 5 days of working on the code everynight, I am not further ahead....
3
by: Ryan | last post by:
I want to create a button on a Windows form that stays depressed when a user clicks it (and raises if they click it again). How do I do this? Thanks, Ryan
1
by: akineko | last post by:
Hello everyone, I'm trying to implement a virtual instrument, which has buttons and displays, using Tkinter+Pmw. One of items on the virtual instrument is a round button. This is imitating a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.