How to lock text boxes? - winforms

I am workig on winform for building up word processor using RTB, it includes some text boxes but they are reserved for special uses (Mail Merge). I dont want user to type in it, how can i avoid him, i mean is there any option for locking these text boxes to prevent user from typing in it?

You can disable the textbox and enable it when required...
textbox1.enabled=false

You can either do:
textbox.Enabled = false
or
textbox.Readonly = true

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.

Make the official WPF RibbonTextBox look like a PasswordBox

I'm developing an application with the official WPF Ribbon system, and I'd like to have a password field up in the ribbon. Is there any way I can modify the RibbonTextBox control to display dots instead of characters, the way a PasswordBox does? Thanks in advance.
Can't you just use the key up event, and take the value out of the box, store it in a variable, and replace it with the character you want?
User presses "A" on key up, you grab the value, store it in a variable, and then replace it with an "*". Keep doing this until they stop typing in the box?

Is there a way of undoing a selection a user makes with the combo box?

In WPF 3.5, is there a property of the combo box will allow the user to undo the selection they've made?
Code
If you look to a way to reset the selection from code (you wrote a property), try the following:
cboYourCombo.SelectedIndex=-1
or
cboYourCombo.SelectedItem=null;
Keyboard Shortcut
If you look for a keyboard shortcut to reset, I've never seen. But if you want, you can do it on your own, it's probably easy:
Attach an EventHandler to the PreviewKeyDown-event of your combobox (or register a general event-handler that works for all comboboxes in your window/app), check the key and if its the key you want to reset, use the code above to reset the selection. Please note, in the PreviewKeyDown-event you can also check for special-keys such as the control-key.
Provide an empty Value
However I think, better would be to add an empty entry and then preselect this empty value. If the user has changed the selection and wants to reset, he can select the empty value. Otherwise you change the standard UI-behaviour and not all people like this.
What do you mean by "undo"? Do you mean something like CTRL+Z (or an undo button), or something like CANCEL? Implementing true undo/ctrl+z on a combo box is something very few applications do, and it will surprise the user. This is a very bad idea, unless you have a very good reason.
If you have a very good reason to go against the design of most windows apps, you can add a handler for SelectionChanged, and implement your own history. Then, if the user either uses a keydown (ctrl+z), or clicks an "undo" button, you can set the selection yourself.
Alternately, if you don't really want an UNDO feature, and actually want a CANCEL feature (a common feature in UI apps), then you shouldn't worry about each control individually. Just keep a set of stored settings (in some custom class), and set all the controls back to the values that were stored. In the case of a combo box, you'd want to set the Selection property.

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

How do you deal with temporary useless controls in Winforms (hiding vs disabling)?

It's quite common to have a form with a checkbox stating "Use foo" immediately followed by a textbox where the user can input the "foo value" he want's to use. Of course, this textbox is useful only if "Use foo" is checked
I don't know the best way to deal with this situation :
Disable the textbox (ie textboxfoo.Enabled=false;)
Hide it (ie textboxfoo.Visible=false;)
Let the user input a foo value if he wants to, and ignore the value he entered.
Is there a best practice that I can follow ?
The textbox should be disabled.
If the textbox is hidden, then the visible alteration of the form will make the program less user-friendly. An example of this is the old (very unpopular) disappearing menu items that used to be in Microsoft Office. People don't want things moving around on their screens. It's disorienting.
If the user is permitted to input a useless value, then that gives the false impression that entering the value has some effect.
Disabling the text box is the best option in this case. The fact that the text box is enabled/disabled as the checkbox is checked/unchecked provides useful feedback to the user: the use foo option expects a foo value, and the foo value is only meaningful if the use foo option is selected.
Hiding the text box is less satisfactory - if the box isn't checked, the user won't realize that enabling the foo option will allow them to specify the foo value. Imagine them thinking to themselves: "I'd better not select the use foo option, as I have no idea what foo value will be used."
The third option is the worst, since doesn't indicate that the entered value will be ignored.
Disable the textbox
With the textbox hidden the user may skip over the option "Use Foo" since it won't be clear to them how they will or should define "foo". With the textbox visible but disabled the user will recognize that they can define "foo" once they say they want to use it.
Clearly disabling the text box is favoured because the user still has a visual clue as to what "Foo" will enable them to do.
But about what about the "More options >>" / "<< Less options" panel that opens up or closes as "Foo" is checked/uncheck? To much work, from the developer's perspective, and/or too much fiddling, from the user's perspective? Myself, I like the way it cleans up the interface, given that the defaults for "Foo" (when hidden) are appropriate.
(Having said that, I don't use that everywhere. Moderation in all good things.)
I favour disabling over hiding, if only because it avoids unnecessary white space on your dialog.
Disable the text box.
It makes it clear to user that there is an option that happens to be unavailable.
Hiding it will sometimes get a user response of "Where did my box go".
Another option would be to let the enter input some data if he wants too, but to auto-check the foo checkbox if he starts typing into the foo textbox.

Resources