Handle non image files, auto hide labels

This commit is contained in:
Jaex 2022-03-16 09:04:32 +03:00
parent 178abbd36c
commit e0665a20ca
2 changed files with 26 additions and 8 deletions

View file

@ -172,8 +172,17 @@ public MyPictureBox()
private void UpdateImageSizeLabel()
{
if (IsValidImage)
{
lblImageSize.Visible = true;
lblImageSize.Text = $"{Image.Width} x {Image.Height}";
lblImageSize.Location = new Point((ClientSize.Width - lblImageSize.Width) / 2, ClientSize.Height - lblImageSize.Height + 1);
}
else
{
lblImageSize.Visible = false;
}
}
public void UpdateTheme()
{
@ -225,9 +234,18 @@ public void LoadImage(Image img)
if (!isImageLoading)
{
Reset();
if (img != null)
{
isImageLoading = true;
Image = (Image)img.Clone();
isImageLoading = false;
}
else
{
Image = null;
}
AutoSetSizeMode();
}
}
@ -310,8 +328,6 @@ private void AutoSetSizeMode()
{
if (IsValidImage)
{
lblImageSize.Text = $"{Image.Width} x {Image.Height}";
if (Image.Width > pbMain.ClientSize.Width || Image.Height > pbMain.ClientSize.Height)
{
pbMain.SizeMode = PictureBoxSizeMode.Zoom;

View file

@ -74,7 +74,7 @@ private void LoadCurrentImage()
private void NavigateImage(int position)
{
if (!SupportsImageNavigation) return;
if (!SupportsImageNavigation || Images.Length < 2) return;
int nextImageIndex = CurrentImageIndex + position;
@ -96,9 +96,10 @@ private void NavigateImage(int position)
private void UpdateIndexLabel()
{
if (!SupportsImageNavigation) return;
if (!SupportsImageNavigation || Images.Length < 2) return;
lblIndex.Text = CurrentImageIndex + 1 + " / " + Images.Length;
lblIndex.Visible = true;
lblIndex.Location = new Point((ClientSize.Width - lblIndex.Width) / 2, -1);
}
@ -226,6 +227,7 @@ private void InitializeComponent()
lblIndex.Font = new Font("Arial", 20f);
lblIndex.Padding = new Padding(5);
lblIndex.TextAlign = ContentAlignment.MiddleCenter;
lblIndex.Visible = false;
Controls.Add(lblIndex);
pbPreview.Cursor = Cursors.Hand;