V
V
Vlad2016-05-28 12:17:51
Windows
Vlad, 2016-05-28 12:17:51

How to properly organize logic in Windows Forms c#?

There is a form with buttons. The functionality of some buttons depends on whether other buttons have been pressed before. For example: 1) if you pressed button A and pressed button B, then button C does operation 1; 2) if you pressed button A and pressed button B, then button C performs operation 2.
What are the best ways to implement this scheme with a minimum of code writing costs? How would you implement?
PS Using bool-variable flags makes you create too much code, which is difficult to keep track of in this form

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Artem Voronov, 2016-05-28
@newross

implement the MVVM or MVP pattern. You can simplify the task even more by switching to WPF.

R
Rou1997, 2016-05-28
@Rou1997

Nonsense, using some special tools in this case will only take extra time, well, maybe I would extend Button by adding the "WasClicked" property, etc., or write an IDE plugin that would automatically generate flags for buttons , but in any case, this is saving on matches, it makes sense to invent something for really time-consuming and frequent tasks.

V
Vitaly Pukhov, 2016-05-31
@Neuroware

I would extend button with the Clicked attribute and create a couple of AND and OR functions that take objects of the button class as parameters. Next, I would compose scripts and a script parser that reads the script and checks the truth of the statement. If the expression is true, executes the function and resets the Clicked flag on all buttons that participated in the expression

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question