简体   繁体   中英

Commands through an interface like Command Prompt

I was wondering is there a way to run an input form a user as a command without using switch or if statements?

For example if I had a form that contained a 10 by 10 picture frame, and wanted to change its size to 100 by 100. Better yet, is there a way to use a string that is defined in code: string newString = ""; then change the name of said string: newString = "newButton" + count;

This code would be used like so:

   for (int count = 0; count < records) // Records being the count of records to   be presented.
          { 
            newString = "newButton" + count;
            Button newString.ToString() = new Button();
          } //Uses the newString to give      ID name to the new buttons.

Some thing similar to this would be using java code to create a table for a servlet using the <tag> and the out_print command.

It seems like maybe you're looking for a Dictionary<T,T> . You could implement your loop idea like this:

var buttons = new Dictionary<string,Button>();
for (int count = 0; count < records)
{ 
    newString = "newButton" + count; 
    var newButton = new Button();
    buttons.Add(newString, newButton);
} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM