|
-
Jun 20th, 2005, 08:47 PM
#1
Thread Starter
New Member
Help For Beginner
I have a matrix of 9x9x9 buttons on my form, labelled 1 through to 9 for the
first lot, and 1 ~ 9 for the second, and so on.
The buttons are made invisible when clicked. The code I use is:
private void button11_Click(object sender, EventArgs e)
{
button11.Visible = false;
}
private void button12_Click(object sender, EventArgs e)
{
button12.Visible = false;
}
etc etc
Question: After designing the form I now have to manually paste the line
buttonxx.Visible = false; for each button and change the xx to the corresponding button number.
9x9x9 = 700plus cut and paste actions. A lot of work, and oh so boring.
Is there an easier way, like a mass paste. In MS Excel for instance, if
you copy a formula into multiple fields, it automatically adjusts the cell numbers.
Would be nice if that works in my case and automatically numbers the
700 buttons.
Rgds, Andreas
-
Jun 20th, 2005, 09:19 PM
#2
Lively Member
Re: Help For Beginner
700 BUTTONS!??!
Whoa. I hope this isn't a business application!
I don't know of a way to do this. There isn't an Excel-like function that will cascade your button identifiers throughout code by copying and pasting. Each button is supposed to be unique.
You could try a control array, but it sounds like each button does something unique. If it does, you're probably stuck coding each one.
Use the code you have as a template and copy and paste it when you access a new button. That would speed things up a little bit.
Anyone else run into this problem?
-
Jun 20th, 2005, 10:26 PM
#3
Thread Starter
New Member
Re: Help For Beginner
Actually, it's for my daughter: to help her solve SuDoku puzzles. The matrix looks something like this: each single digit represents a button.
123 123 123 123 123 123 123 123 123
456 456 456 456 456 456 456 456 456
789 789 789 789 789 789 789 789 789
123 123 123 123 123 123 123 123 123
456 456 ...
789 ...
|
|
V repeated 9 times.
By clicking a button (number) this button is made invisible. Eliminating all incorrect choices will leave her with 1 button(number) per square and thus
providing her with the correct answer.
Any ideas how to make things easier (apart from using commercial SW, this
is after all a father/daughter project)
Rgds, Andreas
-
Jun 21st, 2005, 12:31 PM
#4
Re: Help For Beginner
Yup - use a single event handler:
PHP Code:
Button btn1 = new Button();
btn1.Click += new EventHandler(Button_Click);
// ...
Button btn700 = new Button();
btn700.Click += new EventHandler(Button_Click);
private void Button_Click(object sender, EventArgs e)
{
Button src = (Button) sender;
src.Visible = false;
// Above code can be shortened to:
// ((Button) sender).Visible = false;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|