Reputation: 23
I'm new at C#. I want to add '#' to HALLO (in the textBox) each time when you hover your mouse over the button.
This is what i have:
public partial class Form1 : Form
{
string Q = "HALLO";
string hashtag = "#";
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
tB1.Text = Q;
}
private void bT1_MouseHover(object sender, EventArgs e)
{
tB1.Text += hashtag;
if (Q.Length > 20)
{
tB1.Clear();
}
lBkarakters.Text = Convert.ToString(tB1.Text.Length);
}
}
}
It does add the '#', but HALLO is gone.
Upvotes: 0
Views: 1611
Reputation: 2984
public partial class Form1 : Form
{
string Q = "HALLO";
string hashtag = "#";
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
tB1.Text = Q;
}
private void bT1_MouseHover(object sender, EventArgs e)
{
tB1.Text += hashtag;
}
}
or
public partial class Form1 : Form
{
string Q = "HALLO";
string hashtag = "#";
public Form1()
{
InitializeComponent();
tB1.Text = Q;
}
private void bT1_MouseHover(object sender, EventArgs e)
{
tB1.Text += hashtag;
}
}
Make sure you're event is registered:
Upvotes: 0
Reputation: 26281
Initialize your textbox somewhere (I'd recommend on the Load
event handler):
tB1.Text = "HALLO";
Register an event handler for the MouseHover
event on the button:
this.yourButton.MouseHover += new System.EventHandler(this.yourButton_MouseHover);
// ...
private void yourButton_MouseHover(object sender, System.EventArgs e)
{
tB1.Text += "#";
}
Upvotes: 4