locked
MouseClick event RRS feed

  • 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.
    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.
    Sunday, April 26, 2009 3:16 AM
  • Hi
    try this

     

    private void txtCode_MouseClick(object sender, MouseEventArgs e)

    {

    displaybox.Clear();//ur txtbox name

    }


    Meghana Lohit
    Sunday, 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: 

    http://phjh4q.blu.livefilestore.com/y1p4FSQMnNwd_CMJaA4E-l2XZhPoRlK5UBym8WnbgCSC9nGxvm1GnxcMmnfKNI0lwo4UH_7jmq3VHnBmJoN6mEx-x7uSYZ-2R3r/1.png 
    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. 

    http://phjh4q.blu.livefilestore.com/y1pFwMs1Nor8RhcUGlV9cQ6jQW4HJ3uZWRnx-edZRZsOqFInxpco1wIXXFmZyirNRBgVT-19rwAUx0imOI1QerUhw/2.png 
    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.com
    Sunday, April 26, 2009 9:48 AM