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.
Related
So for the program I'm writing I have an overview of notes the user created. This I created with TextBoxes that are generated from database values. I want the user to not be able to enter and change anything in this overview.
I tried to use tb.ReadOnly = true; but this doesn't disable the entering of the textbox.
After that I tried tb.Enabled = false; but this applies a gray out to all the text.
Is there any way to remove this gray out or just make the TextBox unchangeable without any visual difference?
Create a label with border style as FixedSingle, flat style as Flat, and set padding to 5,5,5,5.
One option is to use a NuGet package such as Guna UI to add custom controls. Using Guna, you can use the Control.DisabledState:
textBox1.DisabledState.FillColor = Color.White;
textBox1.DisabledState.ForeColor = Color.Black;
Note: changing a UI control's disabled state to make it appear enabled is in general, bad practice. This is because a user may try to use the TextBox and get frustrated because the computer will not let them use it.
Or alternatively, you could use a Label instead of a TextBox.
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 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.
I'm making a typing windows program that has two text Boxes,
the first is the Source Text textBox and it is read only,
the other is where the user get to type in the text that is in the source TextBox.
When the user typing a letter in the TypingTextBox, I want that letter to be highlighted in the SourceTextBox..
I tried doing this in a couple of events, but none really worked:
SourceTextBox.Select(TypingTextBox.SelectionStart , 1);
I even Tried Making my own event, Also didn't work.
The thing is, I won't see the SourceTextBox highlighting unless I click on it.
and As I mentioned, I tried putting the above code in events like:
Mouse-Focus-Leave in the SourceTextBox
and: TextChanged in the TypingTextBox.
All didn't work .. :(
and If I manged to do that, Can I change the Highlight color ?
Assuming this is WinForm, you need to set the HideSelection property on the TextBox to "False". As far as changing the highlight colour, none that I'm aware of.
Greetings,
I have a form where employees enter comments in a multiline textbox with a limit of 4000 characters. I have the rows set to 8 (obviously an arbitrary number).
When a supervisor looks at the comments the textbox is disabled so the employee comments cannot be modified.
The problem is when the data extends below row 8. Since the textbox is disabled the scrollbar cannot be moved and the supervisor cannot see all the comments. If I hide the textbox and databind to a label for the supervisor none of the line breaks are maintained and a well written paragraph turns into the biggest run on sentence ever…
Is there a way to enable the scroll bar leaving the text disabled?
Is there a way to preserve the structure of the entry in the label?
Instead of disabling the textbox you should set the ReadOnly property to True. This keeps the scrollbars functional but doesn't allow modification of the textbox.
txtComments.ReadOnly = true;
In supervisor mode, don't put the text into a textbox, put it in a label as you mentioned, with '.Replace("\n", "<br>")' in your code.
Alternatively, show the textbox without disabling it, and just disable the 'save' button. Put a note on the page saying that, "changes made here are not persistent" or something to that effect.
Make the text box read only, and set the fore color to the same shade of grey used in disabled text boxes.
<asp:TextBox ForeColor="#AFAFAF" ReadOnly="true" />
Put the text in a PRE tag, and apply overflow:scroll to it.
Make sure to escape the text using Server.HtmlEncode first.