clear the fields on a win form on click event [closed] - c#

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Hi Guys. I am working on a project using visual studio C#, and here is an image of my win form now what i an doing is entering the value in the fields o this form and saving the to my database but after reloading this form all the previous values are there. want i want is that when i click the SAVE button in this form it must save all the values in my database and then clear all the previous values in the text fields + radio buttons etc.
Please help me what will be the code for this process and where should i write this code?

private void btnSaveCick(object sender,EventArgs e)
{
//save your data here
//after saving your data call the CLearControls() function
ClearControls(this);
}
void ClearControls(Control control)
{
foreach (Control c in control.Controls)
{
if (c is TextBox)
((TextBox)c).Clear();
else if (c is RadioButton)
((RadioButton)c).Checked = false;
else if (c is ComboBox)
((ComboBox)c).SelectedIndex = -1;
if(c.HasChildren)
ClearControls(c);
}
}

Related

checkbox check with text in a label [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 days ago.
Improve this question
This is for C# in visual studios.
This is what i'm wanting to do...
If a label contains any information (value or words) to check the check box.
The label is hidden, and if there is any containing value in label I want the checkbox to be true.
this is my code but it's working?!?
private void checkbox_CheckedChanged(object sender, EventArgs e)
{
if (lblName.Enabled = true)
{
chkLX125.Checked = true;
}
else { MessageBox.Show("Error: Please enter value before proceeding.", "Selection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
chkLX125.Checked = false;}
}
Clearly label shouldn't be true. How should I tell the code, if label contains value to check the box?
Sometimes the simple things get me lol.
Thank you for taking the time to read/help me

Windows form application c# [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am designing a windows form application in c# visual studio. for example i have three textboxes Textbox1 texbox2 and textbox3 i want that when user type a number (integer or float) in textbox1 it is automatically added to the values entered in textbox2 when he press enter and displayed in textbox3 .also texbox1 and 2 clears when the numbers are added in textbox3 , how can i do that ?? thanks in advance.
Can you try this(I think you are wrongly tagged wpf):
//please use Property Window to generate this event
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
this.textBox2.Text += this.textBox1.Text;
this.textBox1.Clear();
}
}

Detect when none of app windows is active/focused [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
How detect when user changes focus from multi-window application (alt+tab e.g.).
I want to detect when none of the app windows is active/focused.
First window is always shown but user can work with up to four windows(none of these is shown as dialog).
Form has a ContainsFocus property that indicates whether the form, or one of its child controls has the input focus. You can check this property for all open forms to detect if the application contains focus or not:
var isActive = Application.OpenForms.Cast<Form>().Any(x=>x.ContainsFocus);
Also as another option:
var isActive = (Form.ActiveForm != null)
If you want to be notified of the state of the application you can handle Activate and Deactivate event of your forms for all forms.
private void f_Deactivate(object sender, EventArgs e)
{
BeginInvoke(new Action(() =>
{
if (Form.ActiveForm == null)
Text = "App Deactivated.";
else
Text = "Still Active";
}));
}

Disable right-click menu in ComboBox in c# [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
My ultimate goal is to make Combobox un-editable. Currently when user makes any selection then ComboBox shows selection and highlights it, therefore user can right-click and cut and delete the text that appears. I have added keyDown method, which prevents user from command such as ctrl + c, ctrl + v and delete. But User can still modify highlighted Text using right-click 'cut', 'copy' and 'paste'. How can i prevent user from modifying the current selection?
Ultimate goal is to make Combobox un-editable.
You could subscribe to KeyDown event and set SuppressKeyPress to true for all other actions other than Ctrl+c and create new ContextMenu to disable all default behavior.
comboBox2.KeyDown += comboBox2_KeyDown;
comboBox2.ContextMenu = new ContextMenu(); //disable right click
void comboBox2_KeyDown(object sender, KeyEventArgs e)
{
if (!(e.Control && e.KeyCode == Keys.C))
{
e.SuppressKeyPress = true;
}
}

Visual studio - toggle switch hiding text blocks? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I am doing a school project and i canĀ“t figure out how to "hide" some text blocks when the toggle switch is on and the opposite? Developing a windows 8 app. Thanks and btw. How do you make a collection from multiple text blocks(XAML)?
private void ToggleSwitch_Toggled(object sender, RoutedEventArgs e)
{
}
Assuming your control structure is fairly flat, you can get by using the Tag property on the TextBox. In your XAML, put some distinct value in the Tag field for each TextBox you want to make toggle-able, like the word 'CanToggle'. Then you can do something like
private void ToggleSwitch_Toggled(object sender, RoutedEventArgs e)
{
foreach (Control currentControl in this.Children)
{
if (currentControl.Tag == "CanToggle")
currentControl.Visible = !currentControl.Visible;
}
}
If your control collection is not flat, then you'll have to figure out how to dig recursively through the collection of controls to locate all the TextBox that you want to toggle. This answer may help.
Visual Studio Main Menu - Edit - Outlining - Toggle All Outlining: Ctrl+M, Ctrl+L
Personally, I use Ctrl+M to "collapse to defininitions" more than anything else though.

Categories