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 3 years ago.
Improve this question
I made a timer, but when I press a button nothing happens.
My code is:
private void button3_Click(object sender, EventArgs e)
{
Instellingen form = new Instellingen();
form.Show();
}
Instellingen.cs code:
public partial class Instellingen : Form
{
public Instellingen()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (radioButton1.Checked == true)
{
MessageBox.Show("text", "text");
}
}
}
The button3 event doesn't even fire (confirmed by adding a breakpoint, it doesn't get there)
Check if the button's event realy connected to the method button3_Click.
Put a breakpoint in the first line of button3_Click and check if the code get there.
Make sure your button's click event is button3_Click. Probably your button's click event is empty.
Related
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 1 year ago.
Improve this question
Good morning everyone!
So, I have 8 textboxes and under those are checkboxes. To those textboxes I'am always receiving data from a serialport and I need to do an average from those values. But I only want to do the average from the textboxes from which I checked the checkbox under them.
How can I add those values to the average formula when selected by checking the checkbox?
If anyone could help, I would really apreciate.
Thanks,
Jonathan
I think you should write something like this :
bool[] CheckBoxList { get; set; } = new bool[8];
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
CheckBoxList[0] = checkBox1.Checked;
CalcAverage();
}
private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
CheckBoxList[1] = checkBox2.Checked;
CalcAverage();
}
in CalcAverage method , Textboxes with a true value in the list are computed.
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 4 years ago.
Improve this question
Everytime I click enter, he deletes the textbox, adds the text of the word into the listbox?
Basically, the code-behind of an Windows Forms App that does what you asked in a REALLY BASIC way, would be the following:
using System.Windows.Forms;
namespace WindowsFormsApp1 {
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if(e.KeyChar == 13) //checks if "enter" was pressed
{
listBox1.Items.Add(textBox1.Text);//adds the text to the list
textBox1.Clear(); //clear the text of the textbox
}
}
} }
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
I'm creating a WPF project based on C#.
While working on my project, I have ran into some troubles in how to create a single instance window (Like if i want to open the window X, it cannot be opened again unless it is closed). I found many articles online but they seemed lika lot of work, that it seemed easier to just disable the button when the window is open and enable it when the window is closed.
On the other hand I thought of an alternative solution which worked, but I want to see if it will be heavy on my system when a lot of windows are created.
The solution is shown below.
public partial class MainWindow : Window
{
Window1 wndw = new Window1();
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
if (!wndw.IsActive)
wndw.Show();
}
}
}
As you can see, i created the window at the start, and when the button to open it is clicked, it checks if it is active or not to show.
If I follow the latter method, will all the windows be loaded on MainWindow creation, or will the components only load when the event window1.show() is launched?
Thank you for your support
This is how I would have done it:
MainWindow code:
Window1 window1 = null; // global reference var
private void btnOpenWin1_Click(object sender, RoutedEventArgs e)
{
if (window1 == null)
{
window1 = new Window1();
window1.Closed += Window1_Closed; // register event to detect when Window1 closed
window1.Show();
}
else
{
window1.Focus();
}
}
// register event to remove Window1 ref to be able to open it again
private void Window1_Closed(object sender, EventArgs e)
{
window1 = null;
}
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
When I click button from Form 1, the data of form 2 will display. So, I click button from form 1 again. The next data will add in new form 2, but form before still display. Therefore I have 2 form display. How could I close form before and display next form?
In order to make this, you need to store the reference to your form and manipulate with it.
What you want - close Form2 every time and open again:
public class Form1
{
private Form2 _form2;
public Button1_Click(object sender, EventArgs e)
{
if (_form2 != null)
{
_form2.Close();
}
_form2 = new Form2();
_form2.Label1.Text = DateTime.Now.ToString(); // or any other actions with form
_form2.Show();
}
}
It will close the previously used form and create a new one every time.
What you can also do - reuse this form and add some kind of "close form" button:
public class Form1
{
private Form2 _form2;
public Button1_Click(object sender, EventArgs e)
{
if (_form2 == null)
{
_form2 = new Form2();
_form2.Show();
}
_form2.Label1.Text = DateTime.Now.ToString(); // or any other actions with form
}
public Button2_Click(object sender, EventArgs e) // close button
{
if (_form2 != null) {
_form2.Close();
_form2 = null;
}
}
}
It will simply create a form at first time, and then just change its text when you click your button.
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 7 years ago.
Improve this question
Hello for everyone I am new here,sorry if this post doens't match with at all with how should be,because It's my first post this.
I am wanting to change the value of the Label when I choose one CheckBox,but It's seems that the Label just changes when I click in the Label.
I was looking for see if the Label had some Events for make work it but I didn't found one.
The Label it's in another groupBox,It's seems like that :
In one GroupBox has 3 CheckBox and i want that when i choosing one or all from that CheckBox will change the value of the Label in the another GroupBox.
Please guys,help me here,I am really wanting to understand why It's not working.
You can just register an event handler for the CheckChanged event and change the label's caption in the event handler :
public partial class Form1 : Form
{
public MyForm()
{
InitializeComponent();
myCheckbox.CheckedChanged += new System.EventHandler(this.checkedChanged);
myCheckbox1.CheckedChanged += new System.EventHandler(this.checkedChanged);
myCheckbox2.CheckedChanged += new System.EventHandler(this.checkedChanged);
}
private void checkedChanged(object sender, EventArgs e)
{
myLabel.Text = "Some text";
}
}
use this code here, but change the event to the control you're looking for
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
label1.Text = "your value here";
}
you can do this by double clicking on the radio button control and then it will generate the event for you and then set your code as per the example here.