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
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 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 2 years ago.
Improve this question
I want to do a filtering algorithm with C#, it will be a textbox and I will enter the forbidden words there. If banned words are found in the text I enter in richtextbox later, the word will be deleted as soon as it is written. How can I do this?
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
string[] badWords = textBox1.Text.Split(',');
string[] myText = richTextBox1.Text.Split(',');
foreach (var badWord in badWords)
{
if (myText.Contains(badWord))
{
richTextBox1.Text.Replace(badWord, "");
}
}
}
C# strings are immutable, you need to assign the Text property of your RichTextBox:
if (myText.Contains(badWord))
{
richTextBox1.Text = richTextBox1.Text.Replace(badWord, "");
}
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 2 years ago.
Improve this question
I want know how to have fixed HeaderColumn width in ListView.
private void listView_ColumnWidthChanging(object sender, ColumnWidthChangingEventArgs e)
{
e.Cancel = true;
e.NewWidth = listView.Columns[e.ColumnIndex].Width;
}
But this method is not resolved.
Can anybody help me solve this problem?
Prevent visual change during mouse move on _ColumnWidthChanging event. And remember previous width of sized column, and that it was user sizing event (not the designed code).
And on _ColumnWidthChanged event check if user sizing event and reset the width of column.
bool ColumnWidthChanging = false;
int ColumnWidthChangingWidth = -1;
private void listView1_ColumnWidthChanging(object sender, ColumnWidthChangingEventArgs e)
{
ColumnWidthChangingWidth = listView1.Columns[e.ColumnIndex].Width;
ColumnWidthChanging = true;
e.Cancel = true;
}
private void listView1_ColumnWidthChanged(object sender, ColumnWidthChangedEventArgs e)
{
if (ColumnWidthChanging)
{
ColumnWidthChanging = false;
listView1.Columns[e.ColumnIndex].Width = ColumnWidthChangingWidth;
}
}
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;
}
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
I want to know how I can validate a phone number in a textbox using this code:
System.Text.RegularExpressions.Regex rphone = new System.Text.RegularExpressions.Regex(#"^((\+){0,1}91(\s){0,1}(\-){0,1}(\s){0,1}){0,1}9[0-9](\s){0,1}(\-){0,1}(\s){0,1}[1-9]{1}[0-9]{7}$");
try:
\+[0-9]{3}\s+[0-9]{3}\s+[0-9]{5}\s+[0-9]{3}
heres a little explaination of pattern above .
\+ -------------|> +sign
[0-9]{3} -------|> matches 0-9 max of 3digit
\s+ ------------|> a whitespace
matches with your sample:
+020 111 94546 333
if you want to validate if the number was completed lets say you got a button then textbox do something like:
private void button1_Click(object sender, EventArgs e)
{
Regex phoneNumpattern = new Regex(#"\+[0-9]{3}\s+[0-9]{3}\s+[0-9]{5}\s+[0-9]{3}");
if (phoneNumpattern.IsMatch(textBox1.Text))
{
MessageBox.Show("OK");
}
else
{
MessageBox.Show("Invalid phone number");
}
}
private void myTextBox_Leave(object sender, EventArgs e)
{
Regex pattern = new Regex(#"^((\+){0,1}91(\s){0,1}(\-){0,1}(\s){0,1}){0,1}9[0-9](\s){0,1}(\-){0,1}(\s){0,1}[1-9]{1}[0-9]{7}$");
if (pattern.IsMatch(myTextBox.Text))
{
MessageBox.Show("OK");
}
else
{
MessageBox.Show("Invalid phone number");
}
}