views:

33

answers:

1

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).

+1  A: 

i think Compiling the "Program" that will be designed by the user would be a terrible idea. What you could do is Serialize the Objects created, and write them to a file that can be deserialised and loaded into your program to display the users created "program". if all the functions will be predefined, you could use a unique Key stored in a new class extended from the Button Class to point to which function you would like linked to the button. you might want to store arrays of objects the user can use that can be "Customized" with all the their Visible properties set to false to start with. Im not sure if the Compilation of the users created program is required, or if using your program as a customizable program by plugging serialized objects into it is possible too.

What is the desired goal of the program exactly?

I hope i help in some way to bring new ideas to your design. If you can give me more information i could try and make some example code for you to look at.

Skintkingle
Thanks for the ideas , i am adding more details about the program itself.
Madi D.
I am compiling the users code to make the resulting exe portable to other pcs, also serializing the user's design occurred to me as an option, however, since he cancreate multiple designs to Release, serializing is more suitable for a save/open features.
Madi D.
how about a complete file structure.say for example All serialized objects in a users program called "Calc" is stored in Calc/. to which the serialized objects are stored in there.That would allow more than 1 design to be made and allow 2 "Button 1"'s to exist in the same space without overwriting eachother.then a single text file with the name of the directory you want your program to load placed in the root.
Skintkingle