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;
}
Related
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 days ago.
Improve this question
I got this time difference calculator and I don't like the DateTimePicker because when I have written the hour's it doesn't automatically jump over to minutes so I would like to change them to texbox, is that possible?
The problem Im having is that I cant use textBox.Value so what do I do?
private void button1_Click(object sender, EventArgs e)
{
TimeSpan result = this.dateTimePicker2.Value - this.dateTimePicker1.Value;
this.textBox1.Text = result.ToString();
string s = this.textBox1.Text;
string[] temparry = textBox1.Text.Split ('.');
textBox1.Text = temparry[0];
}
I would like it to be something more like this
private void button1_Click(object sender, EventArgs e)
{
TimeSpan result = this.texbox2.Value - this.texbox3.Value;
this.textBox1.Text = result.ToString();
string s = this.textBox1.Text;
string[] temparry = textBox1.Text.Split ('.');
textBox1.Text = temparry[0];
}
But it dosnt work
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
In the text box, when I enter a number, the first procedure is executed, and when I enter letters, the second procedure is executed.
private void Button1_Click(object sender, EventArgs e)
{
{
if (textBox1.Text.Contains(letters))
dataGridView1.DataSource = DB.pro1(textBox1.Text, Convert.ToInt32(this.textBox1.Text));
else
dataGridView1.DataSource = DB.pro2(textBox1.Text, Convert.ToInt32(this.textBox1.Text));
}
}
private void Button1_Click(object sender, EventArgs e)
{
int number;
bool isNumeric = int.TryParse(textBox1.Text, out number);
if (isNumeric)
{
dataGridView1.DataSource = DB.pro1(textBox1.Text, number);
}
else
{
dataGridView1.DataSource = DB.pro2(textBox1.Text, number);
}
}
The int.TryParse method is used to attempt to parse the input in textBox1 as an integer. If the parsing is successful, it returns true and the result of the parsing is stored in the number variable. If the parsing fails, it returns false.
Based on the result of the TryParse method, the appropriate method (pro1 or pro2) is called and the data source for dataGridView1 is set accordingly.
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
Im trying to develop a form for an imaginary pet clinic in Visual Studio using C# and it consists of check boxes and a label. The checkboxes represent a service the clinic performs and when checked the price of the service is supposed to be displayed in the label, whenever any other boxes are checked theyre supposed to add to the price and when unchecked take away from the price. I am stuck on how i get the check boxes to have a value to display to the label
for example: the vaccinations checkbox (chkVaccinations) is supposed to cost 35 dollars
How do i get the check box to have a value of 35 and when checked to add to the label value which is zero?
private void chkVaccinations_CheckedChanged(object sender, EventArgs e) {
if (chkVaccinations.Checked)
{
}
else
{
}
private void lblTotalprice_Click(object sender, EventArgs e)
{
}
Tbh your question lacks alot of information to be able to help you, but here is an idea of a solution following your example assuming this is codebehind. If you want a full MVVM solution I can update the answer for that.
EDIT: Made some changed to adapt the answer to your latest request in the comments
private double TotalPrice { get; set; }
private void ComputeTotalPrice(double increment)
{
TotalPrice += increment;
}
private void chkVaccinations_CheckedChanged(object sender, EventArgs e)
{
if (chkVaccinations.Checked)
{
ComputeTotalPrice(priceAssociatedWithThisCheckBox);
}
else
{
ComputeTotalPrice(-priceAssociatedWithThisCheckBox);
}
UpdateLabel();
}
private void UpdateLabel()
{
If you want to show $ with 2 decimals
string formattedPrice = string.Format("{0:0.00}", TotalPrice).Replace(".00","");
lblTotalprice.Text= $"{formattedPrice}$";
}
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 6 years ago.
Improve this question
I have a richtextbox and I want to add a space in between every time I press "."(fullstop).
It should automatically add/insert a space(without pressing the spacebar) after I press fullstop.
This will add a space after a Fullstop(.) has been pressed. You need to use the KeyUp Event.
private void richTextBox1_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.OemPeriod)
richTextBox1.Text += " ";
richTextBox1.SelectionStart = richTextBox1.Text.Length;
}
You can create a method to handle richTextBox.OnKeyUp event so that if the key that is pressed is the fullstop then append your text with the space.
private void RichtextBox1_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
{
// Determine whether the key entered is the period key. Append a space to the textbox if it is.
if(e.KeyCode == Keys.OemPeriod)
{
RichTextBox1.Text += " ";
}
}
Obviously you will have to create this event for your own richTextBox rather than my example of "RichTextBox1"