I'm working in a Windows Form Application, I have a textbox which I want to avoid that gets the focus.
Now I'm using the property Enable but it gives a bad appearance to the form.
Also I tried with this
private void txtMyTextbox_Enter(object sender, EventArgs e)
{
ActiveControl = objMyOtherControl;
}
But like I'm selecting words of that textbox when the event is raise the textbox lose the selection.
If you want to make the textbox unfocusable but you still want be able to select the text, what you are looking for is the ReadOnly property.
Here is an extract from the official DOC:
You can transform an editable Windows Forms text box into a read-only
control. For example, the text box may display a value that is usually
edited but may not be currently, due to the state of the application.
To create a read-only text box Set the TextBox control's ReadOnly
property to true. With the property set to true, users can still
scroll and highlight text in a text box without allowing changes. A
Copy command is functional in a text box, but Cut and Paste commands
are not. Note The ReadOnly property only affects user interaction at
run time. You can still change text box contents programmatically at
run time by changing the Text property of the text box.
Related
I´m trying to set textbox visible = false to avoid user from write on it manually but I still need it to write on it by using a bar code scanner, so I need it to get focused before use the scanner, what would be the better way to do it?
Your best option would be to simply validate that what's entered into the textbox is indeed a bar code. What happens when the scanner breaks down and the user still needs to enter a bar code? Limit it to numbers only.
If that's not an option and you find the scanner doesn't work with hidden or disabled textboxes, then set TabStop = false and Multiline = true, and try setting the text box size to 0x0. Or at least really tiny and make it the same colour as the background. In that case you'd want a label or something to then display the bar code or product info so the user knows the scanning worked.
Another possibility may be to set KeyPreview = true on your form. Then you can handle anything that looks like a bar code in the form's KeyPress event, no matter which control is focused. If numbers start coming in, capture them, and if it turns out not to be a bar code, just forward them to the focused control.
just simply set textbox property size to (0,0) with textbox visible = true
From the question, you want to achieve two things.
Make the textbox invisible before Scanning.
Lock the user from editing the textbox after bar code scanning.
Solution
Set the textbox visibility property to false before Scanning so that it does appear on the screen whatsoever.
Have an event handler after finishing scanning or at the end of your scanning method/function, change the Property of the textbox called Disabled to true.
Hope this helps.
If the purpose of hiding textbox is to not-allow user from editing it, then
you may set the ReadOnly property of texbox to true, then call the .Focus() method
before scanning the barcode. In my experience, after having installed the barcode
reader driver, softwares from accompanying CD, all you have to do is scan the
barcode and it will populate with the barcode-value in human readable format,
on any control in an application that can take user-input. I suggest to use
Readonly property of textbox instead of setting visible = false.
Is it possible to make a ListBox ReadOnly? - Technically yes. Set the "Enabled" property to False.
Selection: None break my program because it's trying to select them from the program, but if a user selects one, I don't want it to change, or highlight. I want all highlighting done by the program, is this possible?
This picture shows what I have on my Form
My problem is, it works perfectly fine, I just want it nicer, by only allowing the user to click on only one of the selections from the red box, while they cannot select one from the blue boxes, but the computer can.
My assumption is that you are using WinForms, not WPF. So a simple way is to add a bool flag for each list control to your form. Then on the Selection changed event prevent the change from occurring unless you've set the bool to true. That will allow you turn on/off selected item changes.
Actually here is a link here, instead of bool just create an int to store the current index for each list box. Upon the Selection changing simply set the SelectedItemIndex to the int variable.
Cancelling ListBox SelectedIndexChange Event
I'm currently working on a Windows 8 app in C# and XAML, and I've decided to implement a ToggleSwitch to change the IsReadOnly property to on or off for certain text boxes.
If off, the text boxes should be IsReadOnly = true, which they are now. If on, they should be set to IsReadOnly = false, which they also do.
However, the main function of the ToggleSwitch is to save the new input in the text boxes once the ToggleSwitch has been toggled from on (not read only) to off (read only). By default, the switch is on off to ensure the text in the text boxes are safe.
In a shorter term:
1. Switch ToggleSwitch from off to on to be able to edit the text
2. Edit the text in the text boxes, or the text boxes you want to change
3. Switch ToggleSwitch from on to off, and the program will save the new text.
I have all the variables etc., and the program works fine, except that the ToggleSwitch doesn't save the new information, as I'm pretty clueless on how this should be done correctly...
Thanks, SOF.
Did you mean you want an all XAML way of doing things? Unfortunately DataTrigger isn't available in WinRT - you could try using VisualStateManager or just call a Save() method in the changed handler for your ToggleSwitch.
I'm attempting to "Tokenize" text inside of a WPF RichTextBox control. Whenever the user types a ";", the text before it is placed into a new TextBox contained within an InlineUiContainer. This allows the text to be programmatically different, and yet still be editable.
I was able to remove the border and make the background transparent so that the text looks to be directly inside of the RichTextBox, as desired; however, if you attempt to select only a portion of the text in a "token" and some text outside of it, the whole text box is selected regardless.
My question then is this: is there a way to make the textbox seamlessly selectable? and perhaps to make it so cursoring left/right with the arrows to move into the textbox rather than cursoring over it?
I just ended up using an extension of the Run class.
I have a .NET forms application using a tab control with several tabs. There are a few elements (a button and a few text boxes) that need to be displayed on every tab. Rather than create 5 seperate elements (including all the appropriate properties), is there a way to create "links" to one element?
For example, when an event occurs, I need a textbox to display the same information in each tab. As it stands, I need to create a new textbox for each tab, then explicitly write to each. It would be easiest to just write to one textbox, then consider the rest "links" which automatically update.
Those controls really ought to be somewhere else than on a TabPage. But you can get what you want by implementing the SelectedIndexChanged event and change the Parent of the control. This sample code keeps the text box on the selected tab:
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) {
textBox1.Parent = tabControl1.SelectedTab;
}
Sorry, there isn't any way to do this. controls on a form are childen of that form, they can't be simultaneously children of multiple forms. (a tab is basically a sub-form).
You could either create an array of references to all of the textboxes that you want to behave the same, and and write to all of them when you write to one of them. Or
keep the text in some location outside of the textbox, and update the textbox on the visible tab when ever the user changes tabs.