开发者

Implementation Advice: Binding a button (Click event) to a function, and to another Control too

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜