how to create fixed length multi line text box - winforms

Need to limit character per line on multiline text box and also need to limit no of lines as well. please help.

You probably need to implement your own control inherited from TextBox - then do your own validation in a TextChanged event handler.

Related

WPF Avalon Edit Make text upper case

I am using C# WPF with Avalon Edit Text Box.
I am trying to make all of the text in the text box uppercase and I get an error with additional message 'No undo group should be open at this point'.
I am using the following code:
a.Text = a.Text.ToUpper();
where "a" is the AvalonEdit.TextEditor
Thank you.
Setting the TextEditor.Text property has the side-effect of clearing the undo stack (just as with the normal WPF TextBox). Clearing the undo stack is only allowed when there's no open undo group.
If you did not intend to clear the undo stack, use the methods on textEditor.Document instead to modify the document. You'll want to avoid replacing the whole text, because that would also reset the selection and caret position (after all, AvalonEdit can't know how your new text is related to the old text).
If you do want to clear the undo stack (e.g. you're switching the view to a different document), you'll have to figure out why an undo group is open. Most likely, your code is running from the event handler of an event that is called while the undo group is still open (e.g. document.TextChanged) -- you might want to switch to a different event instead (e.g. document.UpdateFinished is called after the undo group was closed).
If all you want to do is to upper-case text as it is being input, it's better to modify the text before it is added to the document: handle the TextArea.TextEntering event to cancel any lower-case input (set e.Handled = true;), and instead call TextArea.PerformTextInput() to repeat the text input process with the corresponding upper-case text instead.
For copy-paste, you could handle the attached DataObject.PastingEvent and modify the data to be pasted.

how to do the read more capability in xaml

I want to do this in xaml.
I hope somebody can help.
Thanks!
the only option I can think of is to put the text with TextTrimming set to WordEllipsis, and have a second textblock. then in onloaded check the text property to see if the last characters are ...
but i'm not even sure getting the text will retrieve text after the ellipsis is added.
one option I thought would be to create a custom ellipsis, or to to use some ontrimmed event, but they are not available.

TextBox max/min numeric value

I have a little problem - in my Windows Forms program I have a lot of text boxes. They only can get numeric values between 1 - 1024. "Protecting" the text box form non numeric inputs is no problem. But how can I assure that the value doesn't get higher than 1024? Is there any function or any event I could try to catch and then Handle it on my own? I thought about catching the "TextChanged" Event and then check for the value. But how can I know then which Button was the last one pressed?
Besides I wouldn't like to exchange my Textboxes with any other Controls since they're all implemented right now and it would be a lot of work to exchange them all.
Best Regards
Quendras
You should use the NumericUpDown control and set the Maximum property.
You could try using OnLostFocus on each text box. Then verify the input was numeric, and it's value is greater/equal to 0, and less/equal to 1024.
You could check when that textbox loses focus, and then check its value:
public sub Textbox1_lostFocus() handles textbox1.onLostFocus
If cint(textbox1.text) > 1024 then
'whatever you need to do here
End if
end sub

How do you detect incoming text ctrl-v pasting in a winforms textbox?

I'm making my own commentbox control that inherits from a winforms textbox. One of the things it does is prevent users from entering any characters if the limit has been hit. So on the keypress event I just grab the incoming key (excepting delete and backspace) and add it on to what's in the textbox already, then check and see what the length is. If it is over, then I just set the e.Handled = true and the keypress is halted. This scheme fails me though on an incoming ctrl-v paste event. It registers as a single keychar coming in. So the paste won't come through if I'm right at the limit, but it will go over if there is one character of room left and the paste has two or more characters for instance.
I just need a way to detect that this paste is coming in, and when its coming in I need to know what the length of the string is so I can either stop it from happening or paste as much of it as possible in there.
Thanks!
This is such an idle question. You can just set the MaxLength property of the textbox and it prevents all of this. Duh.

how do I know when a user has selected an auto complete suggestion in a text box?

Using Winforms 2.0
I have a text box with a custom autocompletecollection source and the mode is suggest.
How do I know when the user selects a suggestion?
Thanks
You can simply compare strings (inputed with avaliable). Or use combo box for extended control of inputed values.
i couldn't get you properly.
if you gave suggest Mode.i will explain using Dropdown
if user start entering value in drop down automatically the suggested value populate.if he is entering continuously that new value added to that drop down.
Now let's consider about Text box
when ever you enter text box value you need to save a local file or otherwise then only you can able to support suggest mode.with out having source for that text box how you can know what are the values present that text box.
Explain briefly please
thanks,
KRG

Resources