Customize winforms calendar control [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
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

Related

How can I do a quiz with radiobutton? [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 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
}

C# do (not) call event [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 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.

WPF Window Closing does not work after Cancel [closed]

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".

While entering text into the text box I want the first letter of the text to be capitalized automatically [closed]

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 6 years ago.
Improve this question
I want to make an event that when entering text into the text box the first letter of the text to be capitalized automatically in fastest way.
Try something simple like this:
create a text_changed event on the text box
private void textBox1_TextChanged(object sender, EventArgs e)
{
{
if ((textBox1.Text.Length) == 1)
{
textBox1.Text = textBox1.Text[0].ToString().ToUpper();
textBox1.Select(2, 1);
}
}
}
Should you have issues with the formatting of the text due to other requirements, than it needs to be done in a different way.

Validation MVVM WPF [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
I already set validation in all my output that works fine but I have a lot of view and a next button, I want that button to be disabled every time there is an error in the output, it's already set on IsValid and I did this in the code behind of the view:
private void abc_Click(object sender, RoutedEventArgs e)
{
if (Validation.GetHasError(CinInput) == true|| .......)
Console.WriteLine("+++++++++++++Nope+++++++++++++++++");
else
Console.WriteLine("+++++++++++++OK+++++++++++++++++");
}
I need a solution to bind the the result to my viewmodel so i can set isvalid to false any suggestion?
If you're using data binding then its possible to pass a command or command parameter to the viewmodel.
Looks like you're not following MVVM pattern from your abc_click.
You can access your viewmodel like this from your code behind :
var viewModel = DataContext as ViewModelClassName;
viewModel.SomeBooleanProperty = true; // Or false

Categories

Resources