3

I'm attempting to make a command prompt clone in C# so I can get familiar with using IO. However, instead of just one text body, I created two text boxes (one for the command and another for the "parameters") and a rich text box to view the result of the commands. It may sound confusing and the title may be misleading, but I didn't know how else to word it. Anyway, my question is- how do you make only the current line editable and the rest read-only? And how would I be able to combine the commands and parameters in the two text boxes so I wouldn't need two separate text boxes? I have spent 6 days trying to figure out the logic to implement this but I got nothing.

Here's a picture of the form:

enter image description here

And here's what I want to make it similar to:

enter image description here

pcnThird
  • 2,362
  • 2
  • 19
  • 33
  • 1
    You should check this post http://stackoverflow.com/questions/2425847/current-line-and-column-numbers-in-a-richtextbox-in-a-winforms-application and find if current column is greater than first > in the line... – Nemanja Boric Feb 08 '13 at 01:55
  • 1
    Thanks. I've created a new Windows Forms project to test this out. Now, I'll try to apply this to my program. – pcnThird Feb 08 '13 at 02:02
  • 1
    Have you considered using `ListBox` instead? – Dinah Feb 08 '13 at 02:19
  • 1
    @Dinah, unfortunately, I didn't consider using ListBox. But I already fixed the "make the current line editable" problem. Thanks for the suggestion, tough. I'll consider it for similar projects. – pcnThird Feb 08 '13 at 02:33
  • Now that I think of it, It would of been much easier to make a console application instead of a Windows Forms application... Oh well. – pcnThird Feb 08 '13 at 02:34

1 Answers1

1

I'm not sure if you can do that, but if it was me, and this was a "get it done now" situation (and this is just off the top of my head), I would create a user control to contain the "screen". This user control would have the RTF or list box as the top, and a textbox flush under it.

I would remove the borders and wrap both these controls in a panel that has borders. This would simulate a single control.

The textbox would check for the enter key in one of the key-press events, and the control itself would have events that could be handled by the parent control.

This may be hacky, but it would probably be what I'd do in a last minute situation.

Oh as far as the command and parameter stuff, if you read the textbox as a single value, then split the string into an List or array, you could then define a switch or some other conditional code that would know what to do with parameters (index 1+), based on the value of the first item/index.