我尝试过这个,但它不起作用。支票从来都不是真的,也永远进不去。
private void pictureBoxImageToCrop_MouseLeave(object sender, EventArgs e)
{
// Check if the right mouse button is being held down
if ((Control.MouseButtons & MouseButtons.Left) == MouseButtons.Left)
{
// Perform the desired action when the right mouse button is held down
isDrawing = false;
// Additional actions can be added here if needed
}
isDrawing = false;
}
using System;
using System.Drawing;
using System.Windows.Forms;
public class MainForm : Form
{
private bool _isMouseDown = false;
public MainForm()
{
// Others initialize
// Subscribe to mouse events
this.MouseDown += pictureBoxImageToCrop_MouseDown;
this.MouseMove += pictureBoxImageToCrop_MouseMove;
this.MouseUp += pictureBoxImageToCrop_MouseUp;
}
private void pictureBoxImageToCrop_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
_isMouseDown = true;
}
}
private void pictureBoxImageToCrop_MouseMove(object sender, MouseEventArgs e)
{
if (_isMouseDown)
{
// Check if the mouse pointer is outside the form's bounds
if (!this.ClientRectangle.Contains(this.PointToClient(Cursor.Position)))
{
// Mouse leave event
Console.WriteLine("Mouse left while left button down.");
}
}
}
private void pictureBoxImageToCrop_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
_isMouseDown = false;
}
}
}