Auto hide status label

This commit is contained in:
Jaex 2022-03-24 11:01:17 +03:00
parent 3d57d05895
commit b7ea6e0976

View file

@ -38,11 +38,10 @@ public class ImageViewer : Form
public bool CanNavigate => Images != null && Images.Length > 1; public bool CanNavigate => Images != null && Images.Length > 1;
public bool CanNavigateLeft => CanNavigate && (SupportWrap || CurrentImageIndex > 0); public bool CanNavigateLeft => CanNavigate && (SupportWrap || CurrentImageIndex > 0);
public bool CanNavigateRight => CanNavigate && (SupportWrap || CurrentImageIndex < Images.Length - 1); public bool CanNavigateRight => CanNavigate && (SupportWrap || CurrentImageIndex < Images.Length - 1);
public float NavigationAreaSize { get; set; } = 0.1f;
public string[] Images { get; private set; } public string[] Images { get; private set; }
public int CurrentImageIndex { get; private set; } public int CurrentImageIndex { get; private set; }
private float navigationAreaSize = 0.1f;
private ImageViewer(Image img) private ImageViewer(Image img)
{ {
InitializeComponent(); InitializeComponent();
@ -212,11 +211,11 @@ private void ImageViewer_Deactivate(object sender, EventArgs e)
private void pbPreview_MouseDown(object sender, MouseEventArgs e) private void pbPreview_MouseDown(object sender, MouseEventArgs e)
{ {
if (CanNavigateLeft && e.Location.X < ClientSize.Width * navigationAreaSize) if (CanNavigateLeft && e.Location.X < ClientSize.Width * NavigationAreaSize)
{ {
NavigateImage(-1); NavigateImage(-1);
} }
else if (CanNavigateRight && e.Location.X > ClientSize.Width * (1 - navigationAreaSize)) else if (CanNavigateRight && e.Location.X > ClientSize.Width * (1 - NavigationAreaSize))
{ {
NavigateImage(1); NavigateImage(1);
} }
@ -228,11 +227,13 @@ private void pbPreview_MouseDown(object sender, MouseEventArgs e)
private void pbPreview_MouseMove(object sender, MouseEventArgs e) private void pbPreview_MouseMove(object sender, MouseEventArgs e)
{ {
if (CanNavigateLeft && e.Location.X < ClientSize.Width * navigationAreaSize) lblStatus.Visible = CanNavigate && !new Rectangle(lblStatus.Location, lblStatus.Size).Contains(e.Location);
if (CanNavigateLeft && e.Location.X < ClientSize.Width * NavigationAreaSize)
{ {
Cursor = Cursors.PanWest; Cursor = Cursors.PanWest;
} }
else if (CanNavigateRight && e.Location.X > ClientSize.Width * (1 - navigationAreaSize)) else if (CanNavigateRight && e.Location.X > ClientSize.Width * (1 - NavigationAreaSize))
{ {
Cursor = Cursors.PanEast; Cursor = Cursors.PanEast;
} }
@ -283,6 +284,11 @@ private void pbPreview_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
} }
} }
private void lblStatus_MouseEnter(object sender, EventArgs e)
{
lblStatus.Visible = false;
}
#region Windows Form Designer generated code #region Windows Form Designer generated code
private System.ComponentModel.IContainer components = null; private System.ComponentModel.IContainer components = null;
@ -338,6 +344,7 @@ private void InitializeComponent()
pbPreview.MouseWheel += pbPreview_MouseWheel; pbPreview.MouseWheel += pbPreview_MouseWheel;
pbPreview.KeyDown += pbPreview_KeyDown; pbPreview.KeyDown += pbPreview_KeyDown;
pbPreview.PreviewKeyDown += pbPreview_PreviewKeyDown; pbPreview.PreviewKeyDown += pbPreview_PreviewKeyDown;
lblStatus.MouseEnter += lblStatus_MouseEnter;
ResumeLayout(false); ResumeLayout(false);
} }