GithubHelp home page GithubHelp logo

Comments (2)

cyotek avatar cyotek commented on August 19, 2024

Hello,

This is actually by design - if you look in the constructor I disable double click support with the following line:

this.SetStyle(ControlStyles.StandardDoubleClick, false);

With that said, apparently I forgot to then hide the double click events so you couldn't hook them up easily :)

Off the top of my head I really can't remember why it was that double click was disabled. I just did some limited testing now and couldn't see anything obviously wrong - perhaps there was an issue in the original ImageBox implementation before the default scrollable control implementation was removed.

However, it's definitely something to look into changing if there's no obvious issues.

If you are using the source directly, then you can try commenting out the line directly. If you're using the NuGet package then you have at least two options - if you're inheriting from the ImageBox control then you can simply switch the style back on.

Or, you can hook into the MouseClick event and simulate a double click by using the DateTime.Ticks property in conjunction with SystemInformation.DoubleClickTime to do your own double click detection.

private long _doubleClickTimer;
private Point _firstClickLocation;

private void imageBox_MouseClick(object sender, MouseEventArgs e)
{
  long ticks;

  ticks = DateTime.Now.Ticks;

  if (_doubleClickTimer == 0)
  {
    // first click
    _doubleClickTimer = ticks;
    _firstClickLocation = e.Location;
  }
  else
  {
    long millisecondsSinceLastClick;

    // calculate how long, in milliseconds, it was since the last click
    // (there are 10000 ticks per millisecond)
    millisecondsSinceLastClick = (ticks - _doubleClickTimer) / 10000;

    // reset the timer ready to initialize the next click
    _doubleClickTimer = 0;

    // if the number of milliseconds since the last click is less than the
    // system double click time, then we have a double click
    if (millisecondsSinceLastClick <= SystemInformation.DoubleClickTime)
    {
      Size doubleClickSize;
      int secondClickX;
      int secondClickY;
      int hw;
      int hh;

      // now check the location of the second click compared to the first
      // if it's within the system double click size, then we definitely
      // have a double click. If it's outside, then the user can click
      // REALLY fast (or the delay is quite long), but it should be
      // treat as two separate clicks
      doubleClickSize = SystemInformation.DoubleClickSize;
      secondClickX = e.X;
      secondClickY = e.Y;
      hw = doubleClickSize.Width / 2;
      hh = doubleClickSize.Height / 2;

      if (secondClickX >= _firstClickLocation.X - hw && secondClickX <= _firstClickLocation.X + hw &&
        secondClickY >= _firstClickLocation.Y - hh && secondClickY <= _firstClickLocation.Y + hh)
      {
        // double click!
        // TODO: Check mouse buttons if you only want to use left etc
        Debug.WriteLine("Got a double click!");
      }
    }
  }
}

Edit: I forgot to include hit testing in the above example - you should probably consider the location of the cursor between the two clicks too. You'd use the DoubleClickSize property for that, just store the location of the first click, then in the second click check to make sure they are close enough.

Edit2: I updated the snippet to include the extra hit testing.

Hope this helps!

Regards;
Richard Moss

from cyotek.windows.forms.imagebox.

Prakash19921206 avatar Prakash19921206 commented on August 19, 2024

Thanks for the quick reply!
i commented the constructor and rebuilt the project. its working now :)
Thank you

from cyotek.windows.forms.imagebox.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.