I am developing a small C#-winforms program, that has a feature allowing users to add buttons and different controls at run-time.
The scenario i am facing is as follows:
-
1) User adds a button and sets its properties (through a Dialog).
2) User adds a another control (also sets its properties).
3) User chooses the button and chooses bind from a Menu-strip item.
4) a new dialog will show , a DropDown menu will show all "other controls" , another DropDown will show (pre-coded) functions , users have to choose 1 of the controls and a function to bind them to the button's click event.
5) When the user chooses to release his design, an EXE file will be generated that will have the simple program the user designed (still thinking this step over )
My current implementation idea:
A dictionary will hold all the buttons and their corresponding bound functions and controls.. (Key = buttonID , Value = object or dictionary holding function name and Control ID)..
When the user chooses to "Release" his design , the code will construct the form and all controls as TEXT and use the dictionary to generate the appropriate code button to connect each button's click event to the appropriate Function.
The TEXT will also have another Dictionaries Inserted to it that will map each Button to its bound control (a Dictionary for each function), this will be used when a function gets called to Distinguish between buttons different bound controls.
The TEXT will be inserted into a .cs file that will be compiled to generate the EXE (still still thinking of ways to automate this step ).
I feel like this solution is way too complex and that there might be other simpler solutions.
TIA
EDIT:
This is a simple project , that aims to help non-programmers create their own simple programs , like supermarket inventory , or DVD-store library.
For now it will do simple calculator jobs ( 1 textbox, a couple of buttons and functions like ADD,Subtract and such).