I have a textbox. In that textbox I write Human. Then I click a button, and if the word is human, then on a richtextbox, the word human will appear.
Here's the code I've tried.
private void button3_Click(object sender, EventArgs e)
{
if (textBox4.Text)
{
richTextBox1.Text = "human";
}
}
private void textBox4_TextChanged(object sender, EventArgs e)
{
string value = textBox4.Text;
}
I tried making the textbox into a string so I could use it in the if statement, but it didn't work, so instead I used texbox4.text, but it is still wrong.
You could simply do with this piece of code,
private void button1_Click(object sender, EventArgs e)
{
if(textBox1.Text =="human")
{
richTextBox1.Text = textBox1.Text;
}
}
Related
Through coding, if lets say radioButton2 is checked, how do I have the Text property for the Label label1 change to, for example, "Enter a different value"?
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
}
This is very simple you should keep exploring but just for help
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
if(radioButton2.Checked)
{
label1.Text = "Enter a different value";
}
}
Well, why can't you just set the Text property of label in your event handler like
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
label1.Text = "Enter a different value";
}
i am trying to use SendKeys.Send() to send textbox1.Text to a application ( like notepad ), and i want to disable or remove spaces from the textbox so there is no spaces in the application.
Any help is appreciated!
private void InfoSend_Click(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(3000);
SendKeys.Send(input_info);
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
input_info = textBox1.Text;
}
If user can input white spaces to TextBox then you can write this:
private void InfoSend_Click(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(3000);
input_info = input_info.Replace(" ", string.Empty);
SendKeys.Send(input_info);
}
I try to do a notepad in c#,
I have some problems at delete function,
I want to delete selected text...
private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
{
int a;
a = textBox1.SelectionLength;
textBox1.Text.Remove(textBox1.SelectionStart,a);
}
what is wrong?
Remove will return the truncated string, so you just need to reassign to the TextBox:
private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
{
int a = textBox1.SelectionLength;
textBox1.Text = textBox1.Text.Remove(textBox1.SelectionStart,a);
}
Use SelectedText like this :
textbox1.SelectedText = "";
Hi I'm very new to C# and I was just writing a very basic code could anyone help me out? I am trying to simply show a variable (inputted by the user via the textbox) show up in the message box... Thanks :)
private void button1_Click(object sender, EventArgs e)
{
string name1 = textBox1.Text;
MessageBox.Show = (name1);
textBox1.Text = ("");
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
string name1 = textBox1.Text;
}
It's a method, not a property, so you need to call it using this syntax
MessageBox.Show(name1);
Related, textBox1.Text is a string property so you need to change that syntax to
textBox1.Text = "my string";
Your click event could be rewritten as this:
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(textbox1.Text);
textBox1.Text = "";
}
and this section of code doesn't actually have any significance. name1 is only in scope inside the text changed event handler, and you do nothing with it.
private void textBox1_TextChanged(object sender, EventArgs e)
{
string name1 = textBox1.Text;
}
As the titles suggest I am interested in obtaining the value from 4 combo boxes. All 4 combo boxes are the same in the that they list numbers from 0-9. I would like to take those numbers and assigning them to a single string variable. So for example if users selects (CB1 = 4)(CB2 = 3) (CB3 = 2) (CB4 = 1) I would like to take those selection and assign them to a string variable. Thanks in Advance.
-Nogard
if you are using winforms
string s"";
private void combobox1_SelectedIndexChanged(object sender, EventArgs e)
{
s = combobox1.Text+ combobox2.Text+ combobox3.Text+ combobox4.Text;
}
private void combobox2_SelectedIndexChanged(object sender, EventArgs e)
{
s = combobox1.Text+ combobox2.Text+ combobox3.Text+ combobox4.Text;
}
private void combobox3_SelectedIndexChanged(object sender, EventArgs e)
{
s = combobox1.Text+ combobox2.Text+ combobox3.Text+ combobox4.Text;
}
private void combobox4_SelectedIndexChanged(object sender, EventArgs e)
{
s = combobox1.Text+ combobox2.Text+ combobox3.Text+ combobox4.Text;
}
or call only a selected index change event in all comboboxes since all are doing same