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
I have a small problem, I'm trying to create a math quiz in WPF Apllication, where numbers will randomly pop up, which will be calculated according to the chosen math operation.
Everything works as planned, but now I've gotten to prepare Radiobutton and I have no idea how to come up with it. I would like to do this so that the Radiobuttons would take turns which answer would be correct (so that it was still not the first correctly). I know the answer will have to be written as Radiobutton's content. But I don't know how to set the condition for checking the correctness of the result.
if (firstPoss.Content == result.Text)
{
}
if (secondPoss.Content == result.Text)
{
}
if (thirdPoss.Content == result.Text)
{
}
this IF statement always passes
I will be happy for any advice or nudges in the right direction.
I'm speculating a bit since I do not find your use-case to be clear (perhaps add a picture or visual description?). but i think this should be what you want;
There are a lot of good resources out there, so why don't you start with investigating how the radiobutton works in general?
e.g.
https://wpf-tutorial.com/basic-controls/the-radiobutton-control/
Now we see that the IsChecked property signifies that a certain control is checked - be it by the user or programmatically.
Thus we can check that property:
if(firstPoss.Content == Result.Text && firstPoss.IsChecked)
{
// The result is the same as the 'firstPoss' radiobutton, and the button is checked.
// Debug.WriteLine("User checked the right answer!");
}
// ... etc.
EDIT:
Would something like this work in checking whether the right answer radiobutton is checked?
var answerRadioButtons = new RadioButton[] { firstPoss, secondPoss, thirdPoss };
var correctAnswerButtonFound = false;
foreach(var answerButton in answerRadioButtons)
{
if(answerButton.IsChecked)
{
// The user checked this particular button
if(answerButton.Text == Result.Text)
{
// The user checked this button, and the result text is the same as the radio button text - this means we have the right button
correctAnswerButtonFound = true;
}
}
}
if(correctAnswerButtonFound)
{
// The user pressed the correct answer button
}
else
{
// The user did not press the correct answer button
}
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
I am quite new to this and I am building an easy app in visual studio in C# which is plotting graphs and user can customize them by using checkboxes and radiobuttons. These are linked to events and when checkstate is changed, the event is called and the code do its job. But these events are called even when the checkstate was not changed and all plotted areas reload multiple times which is not very pleasant to the user. Can you please advise me how to call the event only when it is required. It's WinForms. An example is below. I want to display the output in both cases - if the bool value is true or false, the output is dependent on this and the outcome is different.
`
private void CheckBoxCountInvalid_CheckStateChanged(object sender, EventArgs e)
{
if (checkBoxCountInvalid.Checked)
countInvalid = true;
else
countInvalid = false;
ShowOutput();
}
`
An (if else) sounds like if would work fine for that problem.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I have an issue that I can't seem to resolve via Google (likely because I'm not searching the right criteria). I have a Closing Event that checks if a button is enabled and pops a messagebox with a result (Yes/No). If the user says NO, I get the desired results in the app; however, the X in the top right corner stops working. How to I "reinstate" the close button ("X" in the top right hand corner) so it works again if pressed (and also evaluates the logic again).
I tried this: Stackoverflow Question
i don't think I want to play with Visibility of the window. The window doesnt go anywhere. They have dirty data and they need to fix it or have it auto saved.
What I have in the application is:
private void DXWindow_Closing(object sender, CancelEventArgs e)
{
if (BtnPatSave.IsEnabled == false) return;
if (MessageBox.Show(Properties.Resources.PatAcctMsgBox3, Properties.Resources.PatAcctMsgBox1,
MessageBoxButton.YesNo,
MessageBoxImage.Warning) == MessageBoxResult.No)
{
e.Cancel = true;
}
else
{
var patId = TbPatId.Text;
var usl = new UnSetLockValue();
usl.UnSetVal(patId);
Log.Info("Patient Account is now unlocked by user: " + Environment.UserName);
}
}
Thats because you are using the MessageBox class.
It disables the "X" button to allow the user only to provide the values you specify.
If you don't want this behaviour i think you have to create your own "MessageBox".
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
In the system I'm doing , I need a calendar that has only the weekends of each month enabled to be selected , the rest is off ..
How can I do this in C # Winforms ?
I researched on the internet and here at the Forum and found nothing exactly like that, I found some things but I could not do what I want.
Welcomee to stackoverflow,
This option is not available within the current tools. You could go and make a custom control by making a custom DateTimePicker inherited from the standard one. I never done this but this might get you started. or you might be able to do something with this article.
If you don't want to go into custom Controls which will make you spend a lot of time, you could just do something like this:
private void dateTimePicker1_ValueChanged(object sender, EventArgs e) {
var dtp = sender as DateTimePicker;
var selectedDate = dtp.Value;
if (!(selectedDate.DayOfWeek == DayOfWeek.Saturday || selectedDate.DayOfWeek == DayOfWeek.Sunday))
{
var offset = (int)DayOfWeek.Saturday - (int)selectedDate.DayOfWeek;
var saturday = selectedDate + TimeSpan.FromDays(offset);
dtp.Value = saturday;
label1.Text = "only saturday or sunday please";
}
}
and prompt the user with a label message telling him that it has been changed.
There is no specific control in Winforms. Easiest workaround is to use a WPF control and then a Winforms host for WPF control. You can find some details here: https://stackoverflow.com/a/27319756/3330348
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
for example i would like a label increment by 1 point every second.
For example
the label will equal 1, then after one second it will equal 2, then after one second it will equal 3, after one second it will equal 4 etc.
its like for a survival scoring mechanism. See how long you can last without dying.
From toolbar add a timer to your form, set it's interval to 1000 (=1s) and set Enabled to true, write an Tick event handler as below:
var num = int.parse(lbl_increase.Text);
lbl_increase.Text = (num+1).ToString();
you can do it like this
1) drag a timer to your form.
the timer is under the components tab (see picture)
2) click your timer (it is not visible on your form, but it is under your form) and go to the properties tab
3) change 'enabled' to true and change 'interval' to 1000.
4) go to event tab and create an event for 'Tick'
5) add this code in your method :
private void timer1_Tick(object sender, EventArgs e)
{
//Convert the text from your label to an int
int i = Convert.ToInt32(yourLabel.Text);
//increment the int
i++;
//set the text to the value of the int
yourLabel.Text = i.ToString();
}
i hope it helps
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Using combobox at C#, VS 2010, Forms.
After you drop a combobox, you scroll on list of choices with your mouse. Which event triggers this on MSDN Combobox Events
example: list of choices on combobox are apple, banana, chocolate, etc., you point at apple it calls the event, you point on banana it calls the same event, etc.
Also how do I get the values its pointing at?
If there is no event available, can I make one via program?
Been googling for a long time now can't seem to find what I need.
Which event triggers on this...
If you create a combo box and add items, you can set the SelectedIndexChanged event and set it to your own custom event handler, like this:
comboBox1.Items.Add("Apple");
comboBox1.Items.Add("Banana");
comboBox1.Items.Add("chocolate");
comboBox1.SelectedIndexChanged += ComboBox1OnSelectedIndexChanged;
The method receives a sender object that is of type combobox, the only tricky thing is that the signature sets it to an object. Casting it allows us to pull out the value.
private void ComboBox1OnSelectedIndexChanged(object sender, EventArgs eventArgs)
{
myvalue = ((ComboBox)sender).SelectedValue;
}
Seems like you could get what you want from this
Redrawing of owner-drawn winforms combobox items
specifically when
(state & DrawItemState.HotLight) > 0
Let me know if more explanation is in order.
EDIT --
What I mean is, by implementing ownerdraw, you are made aware of what item the mouse is over. When the mouse is over the item, then, per the linked article
((state & DrawItemState.Selected) > 0) || ((state & DrawItemState.HotLight) > 0)
is true.
So in that case you can fire an event as needed with the info the OP wants.