From d1a7d82b4f8ae47e102a925f1326357ec5cd7725 Mon Sep 17 00:00:00 2001 From: Jaex Date: Sun, 27 Mar 2022 11:59:45 +0300 Subject: [PATCH] Added navigation buttons --- ShareX.HelpersLib/Forms/ImageViewer.cs | 65 +++++++++++++++----------- 1 file changed, 39 insertions(+), 26 deletions(-) diff --git a/ShareX.HelpersLib/Forms/ImageViewer.cs b/ShareX.HelpersLib/Forms/ImageViewer.cs index cca74f40e..97d743852 100644 --- a/ShareX.HelpersLib/Forms/ImageViewer.cs +++ b/ShareX.HelpersLib/Forms/ImageViewer.cs @@ -39,9 +39,9 @@ public class ImageViewer : Form public bool CanNavigate => Images != null && Images.Length > 1; public bool CanNavigateLeft => CanNavigate && (SupportWrap || CurrentImageIndex > 0); public bool CanNavigateRight => CanNavigate && (SupportWrap || CurrentImageIndex < Images.Length - 1); - public float NavigationAreaSize { get; set; } = 0.1f; public string[] Images { get; private set; } public int CurrentImageIndex { get; private set; } + public int NavigationButtonWidth { get; set; } = 80; private ImageViewer(Image img) { @@ -220,41 +220,32 @@ private void ImageViewer_Deactivate(object sender, EventArgs e) Close(); } - private void pbPreview_MouseClick(object sender, MouseEventArgs e) + private void lblLeft_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { - if (CanNavigateLeft && e.Location.X < ClientSize.Width * NavigationAreaSize) - { - NavigateImage(-1); - return; - } - else if (CanNavigateRight && e.Location.X > ClientSize.Width * (1 - NavigationAreaSize)) - { - NavigateImage(1); - return; - } + NavigateImage(-1); } + } + private void lblRight_MouseDown(object sender, MouseEventArgs e) + { + if (e.Button == MouseButtons.Left) + { + NavigateImage(1); + } + } + + private void pbPreview_MouseClick(object sender, MouseEventArgs e) + { Close(); } private void pbPreview_MouseMove(object sender, MouseEventArgs e) { lblStatus.Visible = !new Rectangle(lblStatus.Location, lblStatus.Size).Contains(e.Location); - - if (CanNavigateLeft && e.Location.X < ClientSize.Width * NavigationAreaSize) - { - Cursor = Cursors.PanWest; - } - else if (CanNavigateRight && e.Location.X > ClientSize.Width * (1 - NavigationAreaSize)) - { - Cursor = Cursors.PanEast; - } - else - { - Cursor = Cursors.Hand; - } + lblLeft.Visible = CanNavigateLeft && new Rectangle(lblLeft.Location, lblLeft.Size).Contains(e.Location); + lblRight.Visible = CanNavigateRight && new Rectangle(lblRight.Location, lblRight.Size).Contains(e.Location); } private void pbPreview_MouseWheel(object sender, MouseEventArgs e) @@ -323,6 +314,8 @@ private void InitializeComponent() { pbPreview = new MyPictureBox(); lblStatus = new Label(); + lblLeft = new Label(); + lblRight = new Label(); SuspendLayout(); BackColor = SystemColors.Window; @@ -338,10 +331,28 @@ private void InitializeComponent() lblStatus.AutoSize = true; lblStatus.Font = new Font("Arial", 13f); - lblStatus.Padding = new Padding(5); + lblStatus.Padding = new Padding(6); lblStatus.TextAlign = ContentAlignment.MiddleCenter; Controls.Add(lblStatus); + lblLeft.Cursor = Cursors.Hand; + lblLeft.Font = new Font("Arial", 50f, FontStyle.Bold); + lblLeft.Location = new Point(0, 0); + lblLeft.Text = "‹"; + lblLeft.TextAlign = ContentAlignment.MiddleCenter; + lblLeft.Size = new Size(NavigationButtonWidth, Bounds.Height); + lblLeft.MouseDown += lblLeft_MouseDown; + Controls.Add(lblLeft); + + lblRight.Cursor = Cursors.Hand; + lblRight.Font = new Font("Arial", 50f, FontStyle.Bold); + lblRight.Location = new Point(Bounds.Width - NavigationButtonWidth, 0); + lblRight.Text = "›"; + lblRight.TextAlign = ContentAlignment.MiddleCenter; + lblRight.Size = new Size(NavigationButtonWidth, Bounds.Height); + lblRight.MouseDown += lblRight_MouseDown; + Controls.Add(lblRight); + pbPreview.Dock = DockStyle.Fill; pbPreview.DrawCheckeredBackground = true; pbPreview.Location = new Point(0, 0); @@ -363,6 +374,8 @@ private void InitializeComponent() private MyPictureBox pbPreview; private Label lblStatus; + private Label lblLeft; + private Label lblRight; #endregion Windows Form Designer generated code }