CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2015
    Posts
    2

    Action while a button is pressed

    I'm trying to do a repeat action while a button is pressed.

    Private void button1>Clicked(object sender EventArg e)
    {
    while ( "Mouse Left Button Down")
    {
    "Print X"
    }

    "Print T"
    }

    I'm not sure how to check if the Mouse button is pressed.

  2. #2
    Join Date
    May 2002
    Posts
    511

    Re: Action while a button is pressed

    Look at the MouseDown and MouseUp events.

  3. #3
    Join Date
    Nov 2015
    Posts
    2

    Resolved Re: Action while a button is pressed

    Thanks for the suggestion. I did a little more reading and came up with the following.

    I added the 2 event definitions?

    button1.MouseDown += new MouseEventHandler(button1_MouseDown);
    button1.MouseUp += new MouseEventHandler(button1_MouseUp);

    Then I was able to use

    private void button1_MouseDown(object sender, EventArgs e)
    {
    "Print X"
    }


    private void button1_MouseUp(object sender, EventArgs e)
    {
    "Print T"
    }

    This accomplished what I was trying to do.

    Thanks for the help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured