C# winforms: move text from one textbox to another - c#

I have a winform application with two textboxes. The textboxes are multilined and has 5 rows.
When the user enters more than 5 lines of text in the first textbox I want the text to continue in the second textbox. And if he/she deletes text from the first textbox I want the text to move back from the second to the first one...
I have tried to solve this in my code by checking how many rows the first textbox has and moved text between the two textboxes. But it doesnt work that well so I wonder if anyone got a better solution??

You could accomplish this by registering for the TextChanged events on the TextBox controls. Then in the event handler, manually inspect the Text property and set focus to the appropriate control. However, what you are describing sounds like it may lead to an inconsistent user experience.
From a UX standpoint I would suggest changing the approach. First of all do you really need to split the text in the UI, or could it be split afterward in the business layer? If you do need it split in the UI, you could have a single TextBox which allows the user to enter the full text, and below it have 2 read-only textbox's which display the 2 split segments as they type (you would also use the TextChanged event logic to do this as they type).
I hope this helps.

Have you tried checking the visible Characters in the text box? or text box character length?

Related

Make Current Line in Read-Only Rich Text Box Editable

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:
And here's what I want to make it similar to:
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.

Textbox copy paste handling for numbers vs varchar data

I have thousands of text boxes in my winforms application.
I want to disable copy pasting for text boxes for numeric values for text boxes which should allow only numbers (integers).
For ex:
Employee number: 1234567
I tried setting false to the ShortcutsEnabled property of text box , it completely stops disabling the entire copy & paste, which i don't want, i want to allow copy pasting for numbers.
I can get data from clipboard
Clipboard.GetText();
and check whether
Int32.TryParse
to check number/string.
Is there any general approach that i can use instead of going and pinning the code for each code or use regex expression ?
Use a MaskedTextBox or NumericUpDown instead of a TextBox.
Once simple approach to not disabling at all is to just use a numeric masked textbox that way bad input (non-numeric) will be rejected. Not only for copypaste but for direct input also.
Use TextChanged event and check the validate of the current text in it
and if you are going to use that textbox in many win forms so I suggest you create an advance user control of TextBox and overide its TextChanged method.

Suggestions on interface design

I need to design a kind of templating system for text: the user enters a piece of text and types some special markers like (**) inside the text that tell the software that the text (**) will need to be changed to some other content.
What I would like to do, is displaying the user the list of fields that need to be changes so that the user can insert the proper data.
I was thinking about doing that displaying all the text (in a text box) and substitute the (**) chars with a textbox so that the user can enter the text. Is there a way to do that? What do you think of this approach? Do you have better ideas? The point is that I would like to show the user the context in which the substitution takes place.
Thanks.
Why not scan the text and generate textboxes on the fly?
Your code would display the templated text, scan it and then, per templated variable it finds, generate 1 textbox. You list those textboxes, one per line, below the text and as soon as the contents in one textbox change, you update the text so that the user sees what this will look like.

C# wpf: Need to add mouseclick event to certain text within a textbox

I have a textbox with a paragraph of information. There are certain words in the paragraph that i want the user to be able to click on, and when clicked, a different textbox is populated with more information.
I know that you can have the event for the whole textbox, but that isn't want i want. I only want to call that event when certain words within the box are clicked.
Sorry, but I don't think you're going to be able to do it like that. The text in a textbox is a singular value type string, there are no objects for "words" or "letters" which would be necessary to raise such an event.
Your best bet will be to subscribe to the textbox keypressed event and parse the string each time a new letter is added. It may not be beautiful, but it's not a huge overhead.

C# Correct way to design/implement this UI?

This is my first tryst with C#. The form that i have in mind consists
A textfield which will be supplied with the path of an executable.
A "Run" button which will call the executable(cosole app)
The executable console output should be displayed in the rich textbox.
Now when i click on a line in richtext box, i select and get the text in the line. This text maps to some other text info. I need to display this text info as a tooltip over the line.
More explanation:
The output of the exe is displayed in the text box as
Address1=Value
Address2=Value
Now when i click the line "Address1=Value", i map this text to find some info regarding what bits are set like
enable : 1
select : 0 ..etc
this info i need to display as tooltip over the line. Is such a thing possible? Is there better alternative to RTB/tooltip for this problem?
Thanks
Vivek
I would recommend using a ListBox for each string of data returned and then if you use a tooltip it makes alot more sense because you are hovering over a list item specifically not the whole text field.
Using the ListBox and items should make it alot easier to work with overall since it will be separating them into defined items instead of just appending lines to a text box.
Also I think you might have alot of work in store for you for trying to make the text box behave the way you want it to for it to treat each line differently dependent on the text of the line.
If you're using the textbox because later you want to be able to select all the output to copy and paste it I would have the textbox hidden by default and have a button that says like "Toggle Raw Output" that will show/hide the text field so users can get the text easily. While using the ListBox as the primary display for information.
What I understand from your question is that when you click on the line in the RTB, your code scans the text on that line, identifies the extra data associated with that line and then inserts it into the tooltip for the RTB.
Technically I believe that this is possible to do - although I am not 100% sure of the mechanics of inserting tooltip text. However as a user interface feature I would personally not do that as the tooltip text is displayed whenever the mouse pointer is anywhere over the RTB. Thus if a user clicks on line #1, (and sees the data associated from line #1) but hovers the mouse of line #3, they might think that the tooltip is associated with line #3.
You could alleviate my concerns with a strongly worded tooltip, but I feel that what you are doing is misusing the tooltip for something other than what it was intended to be used for. IMHO it may be that you are better off displaying your data with a tree control rather than with a RTB, as the tree control more naturally expresses the functionality that you desire (click on a node, expand it to see details etc).

Categories

Resources