📄 pictureviewer.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.IO;
using System.Resources;
using System.Windows.Forms;
using Addot.Drawing;
namespace Pex
{
/// <summary>
/// Summary description for PictureViewer.
/// </summary>
public class PictureViewer : System.Windows.Forms.Form
{
#region --- Fields ---
private enum BitmapNavigation {BitmapPrevious, BitmapNext};
private FileInfo BitmapFile;
private bool FullScreen = false;
private bool IsMoving = false;
private int MouseX;
private int MouseY;
#endregion
#region --- Controls ---
private System.Windows.Forms.PictureBox pbDisplay;
private System.Windows.Forms.ToolBar tbViewer;
private System.Windows.Forms.ToolBarButton tbbZoomMinus;
private System.Windows.Forms.ToolBarButton tbbZoomPlus;
private System.Windows.Forms.ToolBarButton tbbZoomNone;
private System.Windows.Forms.ToolBarButton tbbFitToScreen;
private System.Windows.Forms.ToolBarButton tbbFullScreen;
private System.Windows.Forms.ImageList ilToolbar;
private System.Windows.Forms.MainMenu mainMenu;
private System.Windows.Forms.ToolBarButton tbbRotateHours;
private System.Windows.Forms.ToolBarButton tbbRotateAntiHours;
private System.Windows.Forms.ToolBarButton tbbPrevious;
private System.Windows.Forms.ToolBarButton tbbNext;
#endregion
#region --- Properties ---
private string PictureName
{
set
{
BitmapFile = new FileInfo(value);
if( pbDisplay.Image != null )
{
pbDisplay.Image.Dispose();
}
pbDisplay.Image = new Bitmap(BitmapFile.FullName);
this.DisplayDefault();
ResourceManager rm = new ResourceManager(GetType().Namespace + "." + "PexRes", this.GetType().Assembly);
this.Text = rm.GetString("PexTitle") + " - " + BitmapFile.Name;
}
}
#endregion
public PictureViewer()
{
Cursor.Current = Cursors.WaitCursor;
//
// Required for Windows Form Designer support
//
InitializeComponent();
}
#region Windows Form Designer generated code
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(PictureViewer));
//
// PictureViewer
//
this.ClientSize = ((System.Drawing.Size)(resources.GetObject("$this.ClientSize")));
this.Font = ((System.Drawing.Font)(resources.GetObject("$this.Font")));
this.Location = new System.Drawing.Point(0, 0);
this.mainMenu = new System.Windows.Forms.MainMenu();
this.Menu = this.mainMenu;
//
// pbDisplay
//
this.pbDisplay = new System.Windows.Forms.PictureBox();
this.pbDisplay.Parent = this;
this.pbDisplay.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pbDisplay.MouseDown += new System.Windows.Forms.MouseEventHandler(this.OnBeginMoving);
//
// ilToolbar
//
this.ilToolbar = new System.Windows.Forms.ImageList();
this.ilToolbar.Images.Add(((System.Drawing.Image)(resources.GetObject("resource"))));
this.ilToolbar.Images.Add(((System.Drawing.Image)(resources.GetObject("resource1"))));
this.ilToolbar.Images.Add(((System.Drawing.Image)(resources.GetObject("resource2"))));
this.ilToolbar.Images.Add(((System.Drawing.Image)(resources.GetObject("resource3"))));
this.ilToolbar.Images.Add(((System.Drawing.Image)(resources.GetObject("resource4"))));
this.ilToolbar.Images.Add(((System.Drawing.Image)(resources.GetObject("resource5"))));
this.ilToolbar.Images.Add(((System.Drawing.Image)(resources.GetObject("resource6"))));
this.ilToolbar.Images.Add(((System.Drawing.Image)(resources.GetObject("resource7"))));
this.ilToolbar.Images.Add(((System.Drawing.Image)(resources.GetObject("resource8"))));
this.ilToolbar.ImageSize = new System.Drawing.Size(16, 16);
//
// tbViewer
//
this.tbViewer = new System.Windows.Forms.ToolBar();
this.tbViewer.Parent = this;
this.tbViewer.ImageList = this.ilToolbar;
this.tbViewer.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.OnToolBarClick);
//
// tbbPrevious
//
this.tbbPrevious = new System.Windows.Forms.ToolBarButton();
this.tbViewer.Buttons.Add(this.tbbPrevious);
this.tbbPrevious.ImageIndex = 0;
//
// tbbNext
//
this.tbbNext = new System.Windows.Forms.ToolBarButton();
this.tbViewer.Buttons.Add(this.tbbNext);
this.tbbNext.ImageIndex = 1;
//
// tbbFitToScreen
//
this.tbbFitToScreen = new System.Windows.Forms.ToolBarButton();
this.tbViewer.Buttons.Add(this.tbbFitToScreen);
this.tbbFitToScreen.ImageIndex = 2;
//
// tbbZoomNone
//
this.tbbZoomNone = new System.Windows.Forms.ToolBarButton();
this.tbViewer.Buttons.Add(this.tbbZoomNone);
this.tbbZoomNone.ImageIndex = 3;
//
// tbbZoomPlus
//
this.tbbZoomPlus = new System.Windows.Forms.ToolBarButton();
this.tbViewer.Buttons.Add(this.tbbZoomPlus);
this.tbbZoomPlus.ImageIndex = 4;
//
// tbbZoomMinus
//
this.tbbZoomMinus = new System.Windows.Forms.ToolBarButton();
this.tbViewer.Buttons.Add(this.tbbZoomMinus);
this.tbbZoomMinus.ImageIndex = 5;
//
// tbbRotateHours
//
this.tbbRotateHours = new System.Windows.Forms.ToolBarButton();
this.tbViewer.Buttons.Add(this.tbbRotateHours);
this.tbbRotateHours.ImageIndex = 6;
//
// tbbRotateAntiHours
//
this.tbbRotateAntiHours = new System.Windows.Forms.ToolBarButton();
this.tbViewer.Buttons.Add(this.tbbRotateAntiHours);
this.tbbRotateAntiHours.ImageIndex = 7;
//
// tbbFullScreen
//
this.tbbFullScreen = new System.Windows.Forms.ToolBarButton();
this.tbViewer.Buttons.Add(this.tbbFullScreen);
this.tbbFullScreen.ImageIndex = 8;
}
#endregion
#region --- HMI interactions ---
protected override void OnActivated(EventArgs e)
{
base.OnActivated (e);
this.PictureName = ImageFileList.Singleton.Current;
}
protected override void OnKeyDown(KeyEventArgs e)
{
if( ( pbDisplay.Width > this.Width ) || ( pbDisplay.Height > this.Height ) )
{
int shiftH = (int)(pbDisplay.Width / 10);
int shiftV = (int)(pbDisplay.Height / 10);
Point current = pbDisplay.Location;
Point newPos = new Point(current.X, current.Y);
switch(e.KeyData)
{
// F21 is always sent, whatever the key pressed
case Keys.F21: break;
case Keys.Left:
newPos.X += shiftH;
pbDisplay.Location = newPos;
break;
case Keys.Right:
newPos.X -= shiftH;
pbDisplay.Location = newPos;
break;
case Keys.Up:
newPos.Y += shiftV;
pbDisplay.Location = newPos;
break;
case Keys.Down:
newPos.Y -= shiftV;
pbDisplay.Location = newPos;
break;
default:
pbDisplay.Location = SizeProcessor.CenterToContainer(this.Size, pbDisplay.Size);
break;
}
}
base.OnKeyDown (e);
}
private void OnToolBarClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
Cursor.Current = Cursors.WaitCursor;
switch(tbViewer.Buttons.IndexOf(e.Button))
{
// Previous
case 0:
this.OnPrevious();
break;
// Next
case 1:
this.OnNext();
break;
// Fit to screen
case 2:
this.OnFitToScreen();
break;
// No zoom
case 3:
this.OnZoomNone();
break;
// Zoom +
case 4:
this.OnZoomPlus();
break;
// Zoom -
case 5:
this.OnZoomMinus();
break;
// Rotate 90
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -