aewarnick Posted February 1, 2003 Posted February 1, 2003 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? Quote C#
Moderators Robby Posted February 1, 2003 Moderators Posted February 1, 2003 You can set Lock = True or in th Click event Focus on another control Quote Visit...Bassic Software
aewarnick Posted February 1, 2003 Author Posted February 1, 2003 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(); } } Quote C#
aewarnick Posted February 1, 2003 Author Posted February 1, 2003 Also, this does not compile: pictureBox1.Lock=true; Quote C#
Moderators Robby Posted February 1, 2003 Moderators Posted February 1, 2003 Sorry, the Locked is only for moving and resizing at design time only. Quote Visit...Bassic Software
Moderators Robby Posted February 1, 2003 Moderators Posted February 1, 2003 At which time do want to enable or disable it? Quote Visit...Bassic Software
Moderators Robby Posted February 1, 2003 Moderators Posted February 1, 2003 No, you said you want to be able to enable/disable it. what is your criteria for doing so? Quote Visit...Bassic Software
aewarnick Posted February 1, 2003 Author Posted February 1, 2003 Well, I would like to be able to set a limit on how many times the user can press that button at certain times. Quote C#
Moderators Robby Posted February 1, 2003 Moderators Posted February 1, 2003 You're not getting me, what constitutes those "certain times"? Quote Visit...Bassic Software
aewarnick Posted February 1, 2003 Author Posted February 1, 2003 Let's just make it simple and say that the picture_Click will be disabled after they use it once. Quote C#
*Experts* Volte Posted February 1, 2003 *Experts* Posted February 1, 2003 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. Quote
aewarnick Posted February 1, 2003 Author Posted February 1, 2003 Works great! But there probably is anotherway to do it. Quote C#
*Experts* Volte Posted February 1, 2003 *Experts* Posted February 1, 2003 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.