views:

49

answers:

2

I am creating a console like application and I am wonder what the best way to prevent the user from editing previously executed commands would be. Right now I am using a KeyPressEventHandler to check where the user is trying to type and essentially ignore it if the caret is somewhere other then the "prompt" portion of the textbox. This functions exactly as desired, it just does not seem to be an ideal solution for a such a basic requirement. I am moderately new to C# so I am not sure what options are available to me, hence asking for suggestions.

+3  A: 

If you just want to write commands at the end then it might be a good solution to separate input from output, with a large MultiLine, ReadOnly TextBox for output and have a separate single line TextBox below for input.

If this is a good solution or not is a usability question that needs a wider understanding of your application to determine.

Albin Sunnanbo
I had originally looked at doing it this way but I did not like how it looked when scrolling through the output and the input textbox remained. I also didn't really want to deal with longer commands being typed into the single line texbox, do I just let it keep going on one line or do I change the textbox so it displays over multiple lines and adjust the size of everything in the window. What I am aiming for now is something similar to Bash or the command prompt in windows. Essentially one text box where typing is limited to a specific area.
phill
A: 

@Phill -- you could simply capture every user-applied keystroke, and for each key pressed...

  • if it's an allowed key (i.e. not the up arrow), then use it to build the user a visible command line
  • if it's not allowed (i.e. the up arrow), capture it (effectively blocking it)

... if I interpreted your concern correctly -- my guess is that a 'pure block' on the up-arrow key would pretty much solve your concern of users editing previously executed lines.

I tossed this idea out because I'm uncertain I properly understood what you're trying to accomplish. ^^

Hardryv
What I am trying to accomplish is pretty much the command prompt in Windows or Bash in Linux. I will be capturing the up arrow to scroll through the history of commands so that's not a problem, it's what happens when someone uses the mouse to set the caret somewhere other then the input line. I still want to allow selecting so text can be copied, I just don't want to allow editing. The question is, do I check every keypress and say "This is an edit, ignore" or "this won't edit, allow" or is there a better way to do it.
phill