This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to use MonthCalender to insert date in text box?
I have textBox1 and MonthCalender1 How I can make the selected date in the calender mapped as a string in textBox1?
try this in selected change event of calender :
protected void MonthCalender1 _SelectionChanged(object sender, EventArgs e)
{
System.DateTime myDate = MonthCalender1 .SelectedDate;
textBox1.Text = myDate.ToString ("dd/MM/yyyy");
}
Related
This question already has answers here:
C# string replace does not actually replace the value in the string [duplicate]
(3 answers)
Closed 5 years ago.
I have a problem with String.Replace method. It is not working for buttonclick events.
i use this code
private void button4_Click(object sender, EventArgs e)
{
textBox3.Text.Replace("apple","");
}
When I press clear button it doesn't remove "apple" words
The replace function does not change the control, it returns a new string.
If textBox3 says "applebananacherry"
String text = textBox3.Text.Replace("apple","");
would leave text with "bananacherry"
What you need is
textBox3.Text = textBox3.Text.Replace("apple", "");
This question already has answers here:
What is a NullReferenceException, and how do I fix it?
(27 answers)
Closed 5 years ago.
I can't get value from form2 combobox. I checked that combobox modifier set to 'Public'.
I get the 'Object not referenced to instance of a object' error. What is the mistake?
//Form1
private DialogIO dio;
private void uosIO_ValueChanged(object sender, EventArgs e)
{
dio = new DialogIO();
dio.Show(); // Open Form2 and Set Some value on Combobox
}
// BGWorker get run call from form2 and run it on form1.
private void bgwCustomIO_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
{
MessageBox.Show(dio.uceMinHour.Text); // Show Combobox Value
}
consider check for null also...
private void bgwCustomIO_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
{
if (dio == null || string.IsNullOrEmpty(dio.uceMinHour.Text))
{
return;
}
MessageBox.Show(dio.uceMinHour.Text); // Show Combobox Value
}
This question already has answers here:
How do I get a TextBox to only accept numeric input in WPF?
(33 answers)
Closed 5 years ago.
I use a WPF application I would like to allow only numbers in a textbox. In a WindowsForm application I would know how I would have to make it.
Unfortunately, there is a KeyPress not in WPF and the "code" functioned also no longer.
How is it right and what is the event?
Here you can see the old code that has worked in Windows Form:
private void tbKreisdurchmesser_KeyPress(object sender, KeyEventArgs e)
{
if (char.IsNumber(e.Key) || e.KeyChar==".")
{
}
else
{
e.Handled = e.KeyChar != (char)Keys.Back;
}
}
You can add Previewtextinput event for textbox and validate the value inside that event using Regex,
private void TextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
var textBox = sender as TextBox;
e.Handled = Regex.IsMatch(e.Text, "[^0-9]+");
}
This question already has answers here:
How can I get the current time in C#? [closed]
(4 answers)
Closed 6 years ago.
I have a form which I need to show the exact time when my button was clicked. How may I "capture" the exact time (hh:mm:ss) when I pressed it?
(please, if the question is duplicated, inform me so I can delete this one)
Use DateTime.Now:
void myButton_Click(object sender, RoutedEventArgs e)
{
// Captures the current time in a DateTime object.
DateTime currentTime = DateTime.Now;
// If you need a string, you can use the ToString method.
string timeString = currentTime.ToString("hh:mm:ss");
}
Use DateTime.Now in your button clicked handler:
protected void btn_Clicked(object sender, EventArgs e)
{
DateTime whenClicked = DateTime.Now;
}
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 TextEdit a user types a word 'hello', i want to now how much time did he taked to write the word 'hello'.If possible i want to know how much time did he taked to type each character. For example the person taked 3 seconds to type the word hello, and it took him 1s to type 'h' and 2s to press 'e'.
-Thanks
If talking about Windows Forms, you can use Control.Leave and Control.Enter events. Something like this.
And you can use TextChanged to see how long it takes for the text to be changed.
DateTime StartTime;
DateTime EndTime;
private void textBox1_Enter(object sender, EventArgs e)
{
MessageBox.Show("Entered");
StartTime = DateTime.Now;
}
private void textBox1_Leave(object sender, EventArgs e)
{
MessageBox.Show("Left");
EndTime = DateTime.Now;
MessageBox.Show("Time in control: " + EndTime.Subtract(StartTime).ToString());
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
MessageBox.Show("Changed at : " + DateTime.Now.Subtract(StartTime).ToString());
StartTime = DateTime.Now;
}