How do you clear a rich text box using a button?
private void clearButton_Click(object sender, EventArgs e)
{
presentedCSRRichText.Text.Clear();
}
it's probably really simple to do and i can't think of how to do it.
private void clearButton_Click(object sender, EventArgs e)
{
presentedCSRRichText.Clear();
}
Related
I have tried to change my labels text in both the form_load and form_shown methods and nothing happens. I don't want to set the text in the properties as I want to use the text in another label later. Ive tried both these methods neither works.
private void History_Load(object sender, EventArgs e)
{
populateHistoryQuestionArray();
historyQ1.Text = historyQuestion[0];
}
and
private void History_Shown(object sender, EventArgs e)
{
populateHistoryQuestionArray();
historyQ1.Text = historyQuestion[0];
}
You must add ToString()
private void History_Load(object sender, EventArgs e)
{
populateHistoryQuestionArray();
historyQ1.Text = historyQuestion[0].ToString();
}
I have been trying to get a rich text box to display the current cpu usage from a variable I created when I click a button, but does not work when I use .appendText because it is an int could anyone show me how to do this?
private void button2_Click(object sender, EventArgs e)
{
}
The AppendText-method only accepts parameters of type string. So you have to convert your int-variable .ToString().
private void button2_Click(object sender, EventArgs e)
{
RichTextBox1.AppendText(yourVariable.ToString());
}
I'm new here and I have a doubt. It is possible to transfer a method to another method?
private void button1_Click(object sender, EventArgs e)
{
}
private void c_Click(object sender, EventArgs e)
{
MessageBox.Show("Transfer OK!!!");
}
private void button2_Click(object sender, EventArgs e)
{
// c_Click ????? ------> button1_Click
}
By clicking on Button2, via code is included c_Click the content within the button1.
Finally, clicking on button1, I need to bring up the "Transfer OK" message. Is this possible?
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("Default Message");
c.PerformClick();
}
private void c_Click(object sender, EventArgs e)
{
MessageBox.Show("Transfer OK!!!");
}
Button.PerformClick Method used to call button click event in any method
I think you can use something like this inside your button2_Click:
button1.PerformClick();
or
c_Click(sender, e);
private void button1_Click(object sender, EventArgs e)
{
c_Click(sender, e);
}
I honestly don't know if I understand your question but based on your comments:
I do not want to run "PerformClick ()" or anything similar. Basically,
it would delete the content of the button1_Click and include C_Click
content within the button1_Click.
Clicking on button1, I need to bring up the "Transfer OK" message.
Button2 will have code that will perform the deletion of button1
content and will include the contents of C_Click event. I guess it's
something using "Delegates" or similar.
You're probably not using the word "Content" in the Windows Forms sense of the word. What I get from that is that when you click button2, you want button1 to start acting like the c_Click button, correct?
If I get you correctly you need to simply remove button1's EventHandler for button1_Click and replace it with c_Click, like so:
private void button1_Click(object sender, EventArgs e)
{
}
private void c_Click(object sender, EventArgs e)
{
MessageBox.Show("Transfer OK!!!");
}
private void button2_Click(object sender, EventArgs e)
{
// c_Click ????? ------> button1_Click
button1.Click -= new EventHandler(button1_Click);
button1.Click +=new EventHandler(c_Click);
}
So that after you click button2, the next time you click on button1, it will do c_Click() instead of button1_Click()
I'm trying to do something very simple ( at least I do think so). I have a Form with a Split Container and each part (they are two at all) has only a textBox and the idea is while I'm writing at textBox1 to visualize this text at textBox2. I figure out how to pass some data from the one box to the other but I don't know how to get the value of the textBox and pass it to the other. An again I want to mention that the 2 textBoxes are in one form, so it should be a pretty easy task I suppose.
Here is my code:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
//how to get the text from textBox1?
textBox2.AppendText("I want to pass the text form textBox1");
}
}
And also, I'm using Visual Studio 2010.
Is it as simple as:-
textBox2.Text = textBox1.Text;
?
private void textBox1_TextChanged(object sender, EventArgs e)
{
textBox2.Text = textBox1.Text;
}
try this
`private void textBox1_TextChanged(object sender, EventArgs e)
{
//how to get the text from textBox1?
textBox2 = textBox1.Text;
}`
If you just want to get the text from textbox1
use this:
private void textBox1_TextChanged(object sender, EventArgs e)
{
//how to get the text from textBox1?
textBox2 = textBox1.Text;
}
but if you want to add the text from textbox1 to textbox2
use this:
private void textBox1_TextChanged(object sender, EventArgs e)
{
//how to get the text from textBox1?
textBox2.AppendText(textbox1.text);
}
I am having an issue with my WinForm application.
Below I have my code for my button that I want to click.
private void button1_Click(object sender, EventArgs e)
{
// Do code.
}
Now I want to run the program on start up, so I have this code below:
private void form_Load(object sender, EventArgs e)
{
this.button1_Click(object sender, EventArgs e);
}
But this does not work. It has red lines under the words: "sender", "EventArgs e"
What am I doing wrong, Please help me?
Any help would be greatly appreciated, thanks!
First if you want to click button that way you should do:
private void form_Load(object sender, EventArgs e)
{
button1.PerformClick();
}
Second,
it is not a good idea to do it anyway, better approach is to create common method that is call in button_click event and form_load event.