473,402 Members | 2,064 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,402 software developers and data experts.

button control

Hello dear ppl!
Do someone know how can I invoke the on_click function of a button
only once?
I want some activity to happen only while I am pressing the button the
first time and not to happen on the other times.
Is it possible? If so,how?
Thanks a lot and Happy New Year!
Nov 16 '05 #1
5 1211
Just disable the button after you are done with it so that it can't be
clicked again.

"juli" <ji****@gmail.com> wrote in message
news:1f**************************@posting.google.c om...
Hello dear ppl!
Do someone know how can I invoke the on_click function of a button
only once?
I want some activity to happen only while I am pressing the button the
first time and not to happen on the other times.
Is it possible? If so,how?
Thanks a lot and Happy New Year!
Nov 16 '05 #2
Hi,

Add a global bool variable and set it to false when the on_click is called
the first time. e.g.:

public void onClick ()
{
if (bFirstTime)
{ // this happens only once
bFirstTime = false;
}
// this happens very time
}

--
Regards,
Peter Jausovec
(http://blog.jausovec.net)
"juli" <ji****@gmail.com> je napisal v sporocilo
news:1f**************************@posting.google.c om ...
Hello dear ppl!
Do someone know how can I invoke the on_click function of a button
only once?
I want some activity to happen only while I am pressing the button the
first time and not to happen on the other times.
Is it possible? If so,how?
Thanks a lot and Happy New Year!

Nov 16 '05 #3
I will add a public variable and will change its values in the END of first
click, and validate next time.

Amrro

"juli" <ji****@gmail.com> wrote in message
news:1f**************************@posting.google.c om...
Hello dear ppl!
Do someone know how can I invoke the on_click function of a button
only once?
I want some activity to happen only while I am pressing the button the
first time and not to happen on the other times.
Is it possible? If so,how?
Thanks a lot and Happy New Year!

Nov 16 '05 #4
Hi,

There is several ways of doing it:

1- Button.Enabled = false
2- keeping a flag ( bool variable ) :
bool used= false;
void onclick(.... )
{
if ( used ) return;
used = true;
3- Unhook the event handler:
Form1_OnLoad( .... )
{
EventHandler ev = new EventHandler( onClick );
button1.Click += ev;
}
void onClick(... )
{
buttton1.Click -= ev;
}

4- Hide the button :
button1.Visible = false;
I would use number 1 , in this case the user see that the button is disabled
and is aware that clicking on it will have no effect.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"juli" <ji****@gmail.com> wrote in message
news:1f**************************@posting.google.c om...
Hello dear ppl!
Do someone know how can I invoke the on_click function of a button
only once?
I want some activity to happen only while I am pressing the button the
first time and not to happen on the other times.
Is it possible? If so,how?
Thanks a lot and Happy New Year!

Nov 16 '05 #5
Juli,

I thought I had sent a message however I do not see it.

I would hidden the button however I tried this what is a direct answer on
your question and I thought that this did work as well.
\\\
private void button1_Click(object sender, System.EventArgs e)
{
//whatever code
this.button1.Click -= new System.EventHandler(this.button1_Click);
}
///
I hope this helps,

Cor
Nov 16 '05 #6

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

Similar topics

25
by: KK | last post by:
Hi, I am using history.go(-1) for implementing the back button functionality. Its working fine but with this exception. 1. The page which is having back button has some hyperlinks on it. ...
9
by: Melissa | last post by:
What is the code to delete a command button from a form? Can the code be run from the click event of the button to be deleted? Thanks! Melissa
5
by: gregarican | last post by:
There is a C# CTI app I'm working on using Visual Studio 2005 at revision level 8.0.50727-7600. I need a couple of Windows Form Button controls to emulate line buttons on a telephone. So I went to...
3
by: usha535140 | last post by:
Hi, Can we use Ajax RoundedCornersExtender control with AJax,tabContainer?
2
sanjib65
by: sanjib65 | last post by:
I try to create a custom control that will say, Hello + ComputerUserName. I have added in my App_Code folder a WelcomeLabel.cs file: // WelcomeLabel.cs using System; using...
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: 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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...

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.