Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have a picturebox that is clickable on my form. I would like to disable the click at a certain time but when I use

 

pictureBox1.Enabled=false;

 

to disable it the gif animation stops. How can I disable the click without stopping the animation?

C#
Posted

How would I make this click event only do these commands once and another set every other time it is clicked? Use a while or for structure with a static variable?

 

private void pictureBox1_Click(object sender, System.EventArgs e)

{

string outputStr = "";

foreach(char myChar in x.Text)

{//even gets spaces:

if(!Char.IsSymbol(myChar)&&(!Char.IsLetter(myChar)))

{

outputStr += myChar.ToString();

}

}

C#
  • *Experts*
Posted

I'm not totally sure if this is a great way to do it, but it's one way. If

you want to stop the code in the click event from firing, you could

simply unhook the event handler for the click event.

 

The code:

pictureBox1.Click -= new System.EventHandler(pictureBox1_Click);

Will stop all click events from being processed and sent to the

'pictureBox1_Click' sub.

  • *Experts*
Posted

Definately there is. Create a boolean variable, like this:

bool doClick = true;

at the top of your form (above all

subs and functions), and then in the click event, do it like this:

private void pictureBox1_Click(object sender, System.EventArgs e)
{ 
 if (doClick) {
   // do whatever you need to do in the click event
   doClick = false;
 }
}

Set it back to true if you want to re-enable the button.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...