ImagePreviewDialog.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. using PaintDotNet.CustomControl;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace PaintDotNet
  12. {
  13. internal class ImagePreviewDialog : PdnBaseForm
  14. {
  15. private AppWorkspace appWorkspace;
  16. /// <summary>
  17. /// 图像面板
  18. /// </summary>
  19. private DocumentWorkspaceWindow documentWorkspace;
  20. /// <summary>
  21. /// 公共按钮
  22. /// </summary>
  23. private CommonControlButtons commonControlButtons;
  24. /// <summary>
  25. /// 底部图标栏
  26. /// </summary>
  27. private Panel panel;
  28. public ImagePreviewDialog(Image image, AppWorkspace appWorkspace)
  29. {
  30. this.appWorkspace = appWorkspace;
  31. InitializeComponent();
  32. this.documentWorkspace = new DocumentWorkspaceWindow(this.appWorkspace);
  33. //
  34. //DocumentWorkspaceWindow
  35. //
  36. this.documentWorkspace.Location = new System.Drawing.Point(0, 0);
  37. this.documentWorkspace.Dock = DockStyle.Fill;
  38. this.documentWorkspace.HookMouseEvents();
  39. this.documentWorkspace.AuxiliaryLineEnabled = false;
  40. this.documentWorkspace.RulersEnabled = false;
  41. this.Controls.Add(this.documentWorkspace);
  42. this.Text = PdnResources.GetString("Menu.Previewpicture.Text");
  43. this.documentWorkspace.Document = Document.FromImage(image);
  44. this.commonControlButtons.Location = new Point((this.Width - this.commonControlButtons.Width) / 2, 0);
  45. this.Resize += new EventHandler(this.Resize_Event);
  46. InitCommonButtonEvent();
  47. }
  48. private void InitCommonButtonEvent()
  49. {
  50. this.commonControlButtons.zoomInButton.Click += new EventHandler(zoomInButton_Click);
  51. this.commonControlButtons.zoomOutButton.Click += new EventHandler(zoomOutButton_Click);
  52. this.commonControlButtons.zoomToWindowButton.Click += new EventHandler(zoomToWindowButton_Click);
  53. this.commonControlButtons.actualSizeButton.Click += new EventHandler(actualSizeButton_Click);
  54. this.commonControlButtons.pointerButton.Click += new EventHandler(pointerButton_Click);
  55. this.commonControlButtons.mobileModeButton.Click += new EventHandler(mobileModeButton_Click);
  56. }
  57. private void zoomInButton_Click(object sender, EventArgs e)
  58. {
  59. this.documentWorkspace.ZoomIn();
  60. }
  61. private void zoomOutButton_Click(object sender, EventArgs e)
  62. {
  63. this.documentWorkspace.ZoomOut();
  64. }
  65. private void zoomToWindowButton_Click(object sender, EventArgs e)
  66. {
  67. this.documentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
  68. }
  69. private void actualSizeButton_Click(object sender, EventArgs e)
  70. {
  71. this.documentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
  72. this.documentWorkspace.ScaleFactor = ScaleFactor.OneToOne;
  73. }
  74. private void pointerButton_Click(object sender, EventArgs e)
  75. {
  76. this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.Pointer;
  77. }
  78. private void mobileModeButton_Click(object sender, EventArgs e)
  79. {
  80. this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.MoveMode;
  81. }
  82. private void Resize_Event(object sender, EventArgs e)
  83. {
  84. this.commonControlButtons.Location = new Point((this.panel.Width - this.commonControlButtons.Width) / 2, 0);
  85. //this.commonControlButtons.Left = (this.panel.Width - this.commonControlButtons.Width) / 2;
  86. }
  87. private void InitializeComponent()
  88. {
  89. this.SuspendLayout();
  90. //
  91. //底部panel
  92. //
  93. this.panel = new Panel();
  94. this.panel.Height = 30;
  95. this.panel.Dock = DockStyle.Bottom;
  96. //
  97. //初始化操作按钮
  98. //
  99. this.commonControlButtons = new CommonControlButtons();
  100. this.commonControlButtons.Height = 30;
  101. this.commonControlButtons.Width = 100;
  102. this.commonControlButtons.HideZoomToWindowAndActualSize();
  103. this.panel.Controls.Add(commonControlButtons);
  104. this.Controls.Add(this.panel);
  105. this.ClientSize = new System.Drawing.Size(907, 546);
  106. this.Name = "ImagePreviewDialog";
  107. this.ResumeLayout(false);
  108. }
  109. }
  110. }