Comments (2)
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.
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)
- Cache visible image portion for painting
- Multiple Text HOT 2
- Image Alignment HOT 2
- Integration with Accord.NET.Framework HOT 1
- VirtualDraw and Scale\Transform HOT 2
- Swipe support? HOT 2
- Wrong selection area when maximizing HOT 2
- Creating and Zooming Graphics
- How to determinate a pixel in the imageBox (Mouse click) with total precision HOT 1
- How to get image Point use mouse position? HOT 1
- Solution to: Exception 'Out of Memory' while drawing a big image HOT 2
- Unable to Crop image HOT 1
- Add ability for transparent background color to be used
- Image graphics disappear when zooming out HOT 2
- Is this project still maintained? What about the nuget package? HOT 2
- Support. Net 5.0 HOT 2
- Wrong scrolling in CanPan method HOT 4
- How to save viewport as bitmap? HOT 1
- Π‘an't distinguish click and panning event HOT 1
- The image has moire patterns when scale 15% HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cyotek.windows.forms.imagebox.