Answered by:
MouseClick event

Question
-
Im trying to use the mouseclick event in a textbox. Once the text box is clicked text in display box(label) should clear..
I've tried two ways...
public void TextBox_Mouse Click(object.....)
{
displaybox.text = "";
}
Or..
...
if (TextBox.MouseClick = new MouseClickEvent(TextBox_MouseClick))
{
displaybox.Text = "";
}
Neither worked.....What am I doing wrong?Sunday, April 26, 2009 1:52 AM
Answers
-
When you add Click event for a textbox using IDE, it will be like below
public void TextBox1_Click(object sender, EventArgs e)
{
displaybox.text = "";
}
The two methods in your code does not match with the above syntax.
Please change and try now.
- Edited by Ramesh Swaminathan Sunday, April 26, 2009 3:18 AM
- Proposed as answer by Ramesh Swaminathan Sunday, April 26, 2009 3:19 AM
- Marked as answer by Bin-ze Zhao Tuesday, April 28, 2009 9:23 AM
Sunday, April 26, 2009 3:16 AM
All replies
-
When you add Click event for a textbox using IDE, it will be like below
public void TextBox1_Click(object sender, EventArgs e)
{
displaybox.text = "";
}
The two methods in your code does not match with the above syntax.
Please change and try now.
- Edited by Ramesh Swaminathan Sunday, April 26, 2009 3:18 AM
- Proposed as answer by Ramesh Swaminathan Sunday, April 26, 2009 3:19 AM
- Marked as answer by Bin-ze Zhao Tuesday, April 28, 2009 9:23 AM
Sunday, April 26, 2009 3:16 AM -
Hi
try this
private void txtCode_MouseClick(object sender, MouseEventArgs e)
{
displaybox.Clear();//ur txtbox name
}
Meghana LohitSunday, April 26, 2009 3:27 AM -
Hi - I think my information can help:
Create a new Windows C# Application (or work on the current ).
Then add a "textBox" from the "ToolBox" in the Visual Studio.
Then add some text that must be there from the beginning:
Figure A: A textbox with value already typed.
Add the following code:
private void textBox1_Click(object sender, EventArgs e) { if (textBox1.Text.Contains("Type something here...")) { textBox1.Text = ""; } else { } } private void Form1_Click(object sender, EventArgs e) { textBox1.Text = "Type something here..."; }
Code-snippet1: A simple C# to handle "textBox" clean in "textBox_click" events.
Figure B: If we now click inside the "textbox" the text will disappear and
it will become clean.
I hope this information helped you solve your problem..
Have a nice day...
Sincerely,
Fisnik
Coder24.comSunday, April 26, 2009 9:48 AM