TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Alan Avery
NA
6
544
Address Form checkbox methods programatically?
Jul 28 2019 3:02 PM
Hello.
That's the name of the program I probably should have started C# with. Instead, I've built a small application that identifies musical keys from individual notes through the application of falsification offsets from identified notes.
The program works, but I've got a dozen tickbox methods that all do exactly the same thing save for
1. A single numerical value which informs the offset falsifier method
2. The name of the checkbox control, which is used to link the boolean value of the truthtable to the checkbox value, and provide forward and backwards functionality (i.e., it sets true on check, and false on uncheck).
There has to be a better way to do this. Ideally, I'd be able to parameterize the control name, and the passed num value. Even more ideally, I would be able to handle all of the tickboxes with a single method, with the linked values bound to the control state rather than repeating myself a dozen times.
Or, just as likely, there is some solution that simply escapes my imagination.
The values in question are highlighted below.
Your input is appreciated.
//Is there a way to handle all of the checkboxes with a single entry?
//Perhaps a way to bind a numerical value to each tickbox,
//which would be passed to a handler method?
private
void
CTick_CheckedChanged(
object
sender, EventArgs e)
{
byte
num = 0
;
Roots[num] =
CTick.Checked
;
//C is Checked, Roots[0] = True, else False
KillMaj();
//Eliminate impossible keys
DisplayKeys();
//Update display
}
//Same thing 11 more times
private
void
CSharpTick_CheckedChanged(
object
sender, EventArgs e)
{
byte
num = 1;
Roots[num] = CSharpTick.Checked;
KillMaj();
DisplayKeys();
}
private
void
DTick_CheckedChanged(
object
sender, EventArgs e)
{
byte
num = 2;
Roots[num] = DTick.Checked;
KillMaj();
DisplayKeys();
}
[... you get the idea]
Reply
Answers (
1
)
Criteria for get the MVP award from c-sharpcorner
How many days would it take for a video to be published?