using PaintDotNet.Actions; using PaintDotNet.Annotation; using PaintDotNet.Annotation.Enum; using PaintDotNet.Annotation.Label; using PaintDotNet.Base; using PaintDotNet.Base.CommTool; using PaintDotNet.Base.SettingModel; using PaintDotNet.File; using PaintDotNet.Setting; using System; using System.Collections; using System.Collections.Generic; using System.Drawing; using System.IO; using System.Linq; using System.Reflection; using System.Windows.Forms; using static PaintDotNet.Base.SettingModel.CustomTxtModel; namespace PaintDotNet.Instrument { /// /// 图像索引 /// internal class ImageIndexDialog : FloatingToolForm { public static ImageIndexDialog imageIndexDialog; private PictureBox pictureBox1; private Panel panel1; public Label lblPreview; #region 控件 /// /// Required designer variable. /// private System.ComponentModel.IContainer components = null; /// /// Clean up any resources being used. /// /// true if managed resources should be disposed; otherwise, false. protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.button10 = new System.Windows.Forms.Button(); this.btn_Hide = new System.Windows.Forms.Button(); this.listView1 = new System.Windows.Forms.ListView(); this.imageList1 = new System.Windows.Forms.ImageList(this.components); this.button7 = new System.Windows.Forms.Button(); this.button8 = new System.Windows.Forms.Button(); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); this.groupBox2 = new System.Windows.Forms.GroupBox(); this.lblPreview = new System.Windows.Forms.Label(); this.btn_DelT3 = new System.Windows.Forms.Button(); this.btn_DelT2 = new System.Windows.Forms.Button(); this.btn_DelT1 = new System.Windows.Forms.Button(); this.btn_AddT3 = new System.Windows.Forms.Button(); this.btn_AddT2 = new System.Windows.Forms.Button(); this.btn_AddT1 = new System.Windows.Forms.Button(); this.label3 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label(); this.comboBox_T3 = new System.Windows.Forms.ComboBox(); this.comboBox_T2 = new System.Windows.Forms.ComboBox(); this.comboBox_T1 = new System.Windows.Forms.ComboBox(); this.btn_SetUp = new System.Windows.Forms.Button(); this.comboBox_Name = new System.Windows.Forms.ComboBox(); this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem3 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem4 = new System.Windows.Forms.ToolStripMenuItem(); this.splitContainer1 = new System.Windows.Forms.SplitContainer(); this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.panel1 = new System.Windows.Forms.Panel(); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); this.contextMenuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout(); this.splitContainer1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); this.panel1.SuspendLayout(); this.SuspendLayout(); // // groupBox1 // this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.groupBox1.Controls.Add(this.button10); this.groupBox1.Controls.Add(this.btn_Hide); this.groupBox1.Controls.Add(this.listView1); this.groupBox1.Controls.Add(this.button7); this.groupBox1.Controls.Add(this.button8); this.groupBox1.Location = new System.Drawing.Point(5, 160); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(178, 367); this.groupBox1.TabIndex = 1; this.groupBox1.TabStop = false; this.groupBox1.Text = "索引列表"; // // button10 // this.button10.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.button10.Location = new System.Drawing.Point(116, 338); this.button10.Name = "button10"; this.button10.Size = new System.Drawing.Size(25, 25); this.button10.TabIndex = 19; this.button10.UseVisualStyleBackColor = true; this.button10.Click += new System.EventHandler(this.button10_Click); // // btn_Hide // this.btn_Hide.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.btn_Hide.Location = new System.Drawing.Point(147, 338); this.btn_Hide.Name = "btn_Hide"; this.btn_Hide.Size = new System.Drawing.Size(25, 25); this.btn_Hide.TabIndex = 18; this.btn_Hide.Text = ">>"; this.btn_Hide.UseVisualStyleBackColor = true; this.btn_Hide.Click += new System.EventHandler(this.btn_Hide_Click); // // listView1 // this.listView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.listView1.HideSelection = false; this.listView1.LargeImageList = this.imageList1; this.listView1.Location = new System.Drawing.Point(7, 20); this.listView1.MultiSelect = false; this.listView1.Name = "listView1"; this.listView1.ShowItemToolTips = true; this.listView1.Size = new System.Drawing.Size(165, 316); this.listView1.TabIndex = 0; this.listView1.UseCompatibleStateImageBehavior = false; this.listView1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.listView1_MouseClick); this.listView1.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.listView1_MouseDoubleClick); // // imageList1 // this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit; this.imageList1.ImageSize = new System.Drawing.Size(256, 256); this.imageList1.TransparentColor = System.Drawing.Color.Transparent; // // button7 // this.button7.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.button7.Location = new System.Drawing.Point(54, 338); this.button7.Name = "button7"; this.button7.Size = new System.Drawing.Size(25, 25); this.button7.TabIndex = 16; this.button7.UseVisualStyleBackColor = true; this.button7.Click += new System.EventHandler(this.button7_Click); // // button8 // this.button8.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.button8.Location = new System.Drawing.Point(85, 338); this.button8.Name = "button8"; this.button8.Size = new System.Drawing.Size(25, 25); this.button8.TabIndex = 15; this.button8.UseVisualStyleBackColor = true; this.button8.Click += new System.EventHandler(this.button8_Click); // // groupBox2 // this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.groupBox2.Controls.Add(this.lblPreview); this.groupBox2.Controls.Add(this.btn_DelT3); this.groupBox2.Controls.Add(this.btn_DelT2); this.groupBox2.Controls.Add(this.btn_DelT1); this.groupBox2.Controls.Add(this.btn_AddT3); this.groupBox2.Controls.Add(this.btn_AddT2); this.groupBox2.Controls.Add(this.btn_AddT1); this.groupBox2.Controls.Add(this.label3); this.groupBox2.Controls.Add(this.label2); this.groupBox2.Controls.Add(this.label1); this.groupBox2.Controls.Add(this.comboBox_T3); this.groupBox2.Controls.Add(this.comboBox_T2); this.groupBox2.Controls.Add(this.comboBox_T1); this.groupBox2.Controls.Add(this.btn_SetUp); this.groupBox2.Controls.Add(this.comboBox_Name); this.groupBox2.Location = new System.Drawing.Point(5, 5); this.groupBox2.MaximumSize = new System.Drawing.Size(366, 149); this.groupBox2.Name = "groupBox2"; this.groupBox2.Size = new System.Drawing.Size(178, 149); this.groupBox2.TabIndex = 25; this.groupBox2.TabStop = false; this.groupBox2.Text = "命名规则"; // // lblPreview // this.lblPreview.AutoEllipsis = true; this.lblPreview.ForeColor = System.Drawing.SystemColors.ControlDarkDark; this.lblPreview.Location = new System.Drawing.Point(6, 44); this.lblPreview.Name = "lblPreview"; this.lblPreview.Size = new System.Drawing.Size(166, 12); this.lblPreview.TabIndex = 29; this.lblPreview.Text = "lblPreview"; // // btn_DelT3 // this.btn_DelT3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.btn_DelT3.Location = new System.Drawing.Point(147, 118); this.btn_DelT3.Name = "btn_DelT3"; this.btn_DelT3.Size = new System.Drawing.Size(25, 25); this.btn_DelT3.TabIndex = 28; this.btn_DelT3.Text = "-"; this.btn_DelT3.UseVisualStyleBackColor = true; this.btn_DelT3.Click += new System.EventHandler(this.btn_DelT3_Click); // // btn_DelT2 // this.btn_DelT2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.btn_DelT2.Location = new System.Drawing.Point(147, 93); this.btn_DelT2.Name = "btn_DelT2"; this.btn_DelT2.Size = new System.Drawing.Size(25, 25); this.btn_DelT2.TabIndex = 27; this.btn_DelT2.Text = "-"; this.btn_DelT2.UseVisualStyleBackColor = true; this.btn_DelT2.Click += new System.EventHandler(this.btn_DelT2_Click); // // btn_DelT1 // this.btn_DelT1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.btn_DelT1.Location = new System.Drawing.Point(147, 68); this.btn_DelT1.Name = "btn_DelT1"; this.btn_DelT1.Size = new System.Drawing.Size(25, 25); this.btn_DelT1.TabIndex = 26; this.btn_DelT1.Text = "-"; this.btn_DelT1.UseVisualStyleBackColor = true; this.btn_DelT1.Click += new System.EventHandler(this.btn_DelT1_Click); // // btn_AddT3 // this.btn_AddT3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.btn_AddT3.Location = new System.Drawing.Point(123, 118); this.btn_AddT3.Name = "btn_AddT3"; this.btn_AddT3.Size = new System.Drawing.Size(25, 25); this.btn_AddT3.TabIndex = 25; this.btn_AddT3.Text = "+"; this.btn_AddT3.UseVisualStyleBackColor = true; this.btn_AddT3.Click += new System.EventHandler(this.btn_AddT3_Click); // // btn_AddT2 // this.btn_AddT2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.btn_AddT2.Location = new System.Drawing.Point(123, 93); this.btn_AddT2.Name = "btn_AddT2"; this.btn_AddT2.Size = new System.Drawing.Size(25, 25); this.btn_AddT2.TabIndex = 24; this.btn_AddT2.Text = "+"; this.btn_AddT2.UseVisualStyleBackColor = true; this.btn_AddT2.Click += new System.EventHandler(this.btn_AddT2_Click); // // btn_AddT1 // this.btn_AddT1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.btn_AddT1.Location = new System.Drawing.Point(123, 68); this.btn_AddT1.Name = "btn_AddT1"; this.btn_AddT1.Size = new System.Drawing.Size(25, 25); this.btn_AddT1.TabIndex = 23; this.btn_AddT1.Text = "+"; this.btn_AddT1.UseVisualStyleBackColor = true; this.btn_AddT1.Click += new System.EventHandler(this.btn_AddT1_Click); // // label3 // this.label3.AutoSize = true; this.label3.Location = new System.Drawing.Point(6, 123); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(23, 12); this.label3.TabIndex = 22; this.label3.Text = "T3:"; // // label2 // this.label2.AutoSize = true; this.label2.Location = new System.Drawing.Point(6, 99); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(23, 12); this.label2.TabIndex = 21; this.label2.Text = "T2:"; // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(6, 74); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(23, 12); this.label1.TabIndex = 20; this.label1.Text = "T1:"; // // comboBox_T3 // this.comboBox_T3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); this.comboBox_T3.FormattingEnabled = true; this.comboBox_T3.Location = new System.Drawing.Point(35, 120); this.comboBox_T3.Name = "comboBox_T3"; this.comboBox_T3.Size = new System.Drawing.Size(82, 20); this.comboBox_T3.TabIndex = 19; this.comboBox_T3.TextUpdate += new System.EventHandler(this.comboBox_T3_TextUpdate); // // comboBox_T2 // this.comboBox_T2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); this.comboBox_T2.FormattingEnabled = true; this.comboBox_T2.Location = new System.Drawing.Point(35, 96); this.comboBox_T2.Name = "comboBox_T2"; this.comboBox_T2.Size = new System.Drawing.Size(82, 20); this.comboBox_T2.TabIndex = 18; this.comboBox_T2.TextUpdate += new System.EventHandler(this.comboBox_T2_TextUpdate); // // comboBox_T1 // this.comboBox_T1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); this.comboBox_T1.FormattingEnabled = true; this.comboBox_T1.Location = new System.Drawing.Point(35, 71); this.comboBox_T1.Name = "comboBox_T1"; this.comboBox_T1.Size = new System.Drawing.Size(82, 20); this.comboBox_T1.TabIndex = 17; this.comboBox_T1.TextUpdate += new System.EventHandler(this.comboBox_T1_TextUpdate); // // btn_SetUp // this.btn_SetUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.btn_SetUp.Location = new System.Drawing.Point(147, 16); this.btn_SetUp.Name = "btn_SetUp"; this.btn_SetUp.Size = new System.Drawing.Size(25, 25); this.btn_SetUp.TabIndex = 16; this.btn_SetUp.Text = "*"; this.btn_SetUp.UseVisualStyleBackColor = true; this.btn_SetUp.Click += new System.EventHandler(this.btn_SetUp_Click); // // comboBox_Name // this.comboBox_Name.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); this.comboBox_Name.FormattingEnabled = true; this.comboBox_Name.Location = new System.Drawing.Point(7, 18); this.comboBox_Name.Name = "comboBox_Name"; this.comboBox_Name.Size = new System.Drawing.Size(128, 20); this.comboBox_Name.TabIndex = 0; // // contextMenuStrip1 // this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripMenuItem1, this.toolStripMenuItem2, this.toolStripMenuItem3, this.toolStripMenuItem4}); this.contextMenuStrip1.Name = "contextMenuStrip1"; this.contextMenuStrip1.Size = new System.Drawing.Size(125, 92); // // toolStripMenuItem1 // this.toolStripMenuItem1.Name = "toolStripMenuItem1"; this.toolStripMenuItem1.Size = new System.Drawing.Size(124, 22); this.toolStripMenuItem1.Text = "保存"; this.toolStripMenuItem1.Click += new System.EventHandler(this.toolStripMenuItem1_Click); // // toolStripMenuItem2 // this.toolStripMenuItem2.Name = "toolStripMenuItem2"; this.toolStripMenuItem2.Size = new System.Drawing.Size(124, 22); this.toolStripMenuItem2.Text = "另存"; this.toolStripMenuItem2.Click += new System.EventHandler(this.toolStripMenuItem2_Click); // // toolStripMenuItem3 // this.toolStripMenuItem3.Name = "toolStripMenuItem3"; this.toolStripMenuItem3.Size = new System.Drawing.Size(124, 22); this.toolStripMenuItem3.Text = "强制关闭"; this.toolStripMenuItem3.Click += new System.EventHandler(this.toolStripMenuItem3_Click); // // toolStripMenuItem4 // this.toolStripMenuItem4.Name = "toolStripMenuItem4"; this.toolStripMenuItem4.Size = new System.Drawing.Size(124, 22); this.toolStripMenuItem4.Text = "复制"; this.toolStripMenuItem4.Click += new System.EventHandler(this.toolStripMenuItem4_Click); // // splitContainer1 // this.splitContainer1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; this.splitContainer1.Location = new System.Drawing.Point(0, 0); this.splitContainer1.Name = "splitContainer1"; // // splitContainer1.Panel1 // this.splitContainer1.Panel1.Controls.Add(this.groupBox2); this.splitContainer1.Panel1.Controls.Add(this.groupBox1); this.splitContainer1.Panel1.SizeChanged += new System.EventHandler(this.splitContainer1_Panel1_SizeChanged); this.splitContainer1.Panel1MinSize = 188; // // splitContainer1.Panel2 // this.splitContainer1.Panel2.Controls.Add(this.pictureBox1); this.splitContainer1.Panel2MinSize = 0; this.splitContainer1.Size = new System.Drawing.Size(810, 532); this.splitContainer1.SplitterDistance = 188; this.splitContainer1.TabIndex = 26; // // pictureBox1 // this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.pictureBox1.Location = new System.Drawing.Point(3, 3); this.pictureBox1.Name = "pictureBox1"; this.pictureBox1.Size = new System.Drawing.Size(610, 524); this.pictureBox1.TabIndex = 2; this.pictureBox1.TabStop = false; this.pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint); this.pictureBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown); this.pictureBox1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseMove); // // panel1 // this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left))); this.panel1.Controls.Add(this.splitContainer1); this.panel1.Location = new System.Drawing.Point(4, 5); this.panel1.Name = "panel1"; this.panel1.Size = new System.Drawing.Size(810, 532); this.panel1.TabIndex = 27; this.panel1.SizeChanged += new System.EventHandler(this.panel1_SizeChanged); // // ImageIndexDialog // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(818, 542); this.Controls.Add(this.panel1); this.MinimumSize = new System.Drawing.Size(212, 489); this.Name = "ImageIndexDialog"; this.Text = "图像索引"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.ImageIndexDialog_FormClosing); this.SizeChanged += new System.EventHandler(this.ImageIndexDialog_SizeChanged); this.Resize += new System.EventHandler(this.ImageIndexDialog_Resize); this.Controls.SetChildIndex(this.panel1, 0); this.groupBox1.ResumeLayout(false); this.groupBox2.ResumeLayout(false); this.groupBox2.PerformLayout(); this.contextMenuStrip1.ResumeLayout(false); this.splitContainer1.Panel1.ResumeLayout(false); this.splitContainer1.Panel2.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); this.splitContainer1.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); this.panel1.ResumeLayout(false); this.ResumeLayout(false); } #endregion private System.Windows.Forms.GroupBox groupBox1; public System.Windows.Forms.ListView listView1; private System.Windows.Forms.ImageList imageList1; #endregion private AppWorkspace AppWorkspace; private ConfigModel config = Startup.instance.configModel; /// /// 当前document的图片 /// private Bitmap imageMat; /// /// picturebox中图片对应矩形 /// private Rectangle imageRect; /// /// picturebox中红框对应矩形 /// private Rectangle zoomRect; /// /// picturebox中红框的最小宽度(原图放大3200%) /// private int minRectWidth; /// /// picturebox中红框的最小高度(原图放大3200%) /// private int minRectHeight; /// /// 当前document窗口与其缩放后的图片宽度比例 /// private double widthRatio; /// /// 当前document窗口与其缩放后的图片高度比例 /// private double heightRatio; /// /// picturebox中缩略图与document中缩放后图片的宽度比例(计算滚动条使用) /// private double scRatioWidth; /// /// picturebox中缩略图与document中缩放后图片的高度比例(计算滚动条使用) /// /// 是否重置picturebox中的矩形尺寸 /// private bool isFirst = true; /// /// 是否为拖动picturebox中的矩形框 /// private bool isMoved = false; /// /// 是否为修改picturebox中的矩形框大小 /// private bool isResized = false; /// /// 1-T1,2-T2,3-T3 /// private int CurrentLocation = -1; /// /// 折叠状态,拉伸窗体,最小宽度等于最大宽度时延展宽度 /// public int extendWidth = 200; /// /// 折叠后,最小宽度与最大宽度相等时,固定展开宽度值 /// public int fixedWidth = 834; private Button button8; private Button button7; private ToolTip toolTip1; private Button btn_Hide; private GroupBox groupBox2; private Button btn_DelT3; private Button btn_DelT2; private Button btn_DelT1; private Button btn_AddT3; private Button btn_AddT2; private Button btn_AddT1; private Label label3; private Label label2; private Label label1; public ComboBox comboBox_T3; public ComboBox comboBox_T2; public ComboBox comboBox_T1; private Button btn_SetUp; private ComboBox comboBox_Name; private Button button10; private ContextMenuStrip contextMenuStrip1; private ToolStripMenuItem toolStripMenuItem1; private ToolStripMenuItem toolStripMenuItem2; private ToolStripMenuItem toolStripMenuItem3; private ToolStripMenuItem toolStripMenuItem4; public SplitContainer splitContainer1; /// /// 辅助计算偏移量 /// private Point lastPoint = new Point(0, 0); public int fromMaxSize = 0;//折叠前窗体宽度 public int fromMinSize = 0;//折叠后窗体宽度 public ImageIndexDialog(AppWorkspace AppWorkspace) { imageIndexDialog = this; //this.fromMaxSize = this.Width; this.AppWorkspace = AppWorkspace; InitializeComponent(); CollapseUnfold(); InitializeButtonBackgroudImage(); InitializeToolTipAndEvent(); this.Text = PdnResources.GetString("Menu.Tools.ImageIndex.Text"); this.groupBox1.Text = PdnResources.GetString("Menu.tool.Imageindex.Indexlist.text"); this.groupBox2.Text = PdnResources.GetString("Menu.Set.Generalsettings.Namingrules.text"); // // dialog // this.StartPosition = FormStartPosition.CenterScreen; this.Text = PdnResources.GetString("Menu.Tools.ImageIndex.Text"); // // 设置listview事件 // this.listView1.SelectedIndexChanged += new EventHandler(ListViewSelectedIndexChanged); comboBox_Name_Refresh(); NamingInitialization(); // // 初始化数据 // this.InitData(); this.listView1.View = View.LargeIcon; //PreviewRefresh(); //SplitContainerSize(); PreviewRefresh(config.CaptureSaveMode); } //初始化折叠与展开初始值 private void CollapseUnfold() { this.fromMinSize = splitContainer1.Panel1.Width; this.fromMaxSize = this.Width; if (btn_Hide.Text == "<<") this.MaximumSize = new Size(0, 0); else this.MaximumSize = new Size(400, Screen.PrimaryScreen.Bounds.Height); this.groupBox1.MaximumSize = new Size(366, Screen.PrimaryScreen.Bounds.Height); } private void InitializeButtonBackgroudImage() { this.button7.FlatStyle = FlatStyle.Flat; this.button7.FlatAppearance.BorderSize = 0; this.button7.BackgroundImageLayout = ImageLayout.Center; this.button7.BackgroundImage = PdnResources.GetImageResource("Icons.ProjectEngineering.ListMode.png").Reference; this.button8.FlatStyle = FlatStyle.Flat; this.button8.FlatAppearance.BorderSize = 0; this.button8.BackgroundImageLayout = ImageLayout.Center; this.button8.BackgroundImage = PdnResources.GetImageResource("Icons.ProjectEngineering.PicMode.png").Reference; this.button10.FlatStyle = FlatStyle.Flat; this.button10.FlatAppearance.BorderSize = 0; this.button10.BackgroundImageLayout = ImageLayout.Center; this.button10.BackgroundImage = PdnResources.GetImageResource("Icons.MenuFileBulkSaveIcon.png").Reference; this.toolStripMenuItem1.Image = PdnResources.GetImageResource("Icons.MenuFileSaveIcon.png").Reference; this.toolStripMenuItem2.Image = PdnResources.GetImageResource("Icons.MenuFileSaveAsIcon.png").Reference; this.toolStripMenuItem3.Image = PdnResources.GetImageResource("Icons.MenuFileCloseIcon.png").Reference; this.toolStripMenuItem4.Image = PdnResources.GetImageResource("Icons.MenuEditCopyIcon.png").Reference; } /// /// 初始化提示信息及按钮事件 /// private void InitializeToolTipAndEvent() { this.toolTip1 = new ToolTip(); this.toolTip1.SetToolTip(this.button7, PdnResources.GetString("Menu.tool.Templatemanent.Listmode.text")); this.toolTip1.SetToolTip(this.button8, PdnResources.GetString("Menu.tool.Templategement.Thumbnailmode.text")); this.toolTip1.SetToolTip(this.button10, "批量保存"); this.toolTip1.SetToolTip(this.btn_Hide, "折叠&展开"); this.toolTip1.ShowAlways = true; } /// /// ListView选择事件 /// /// /// private void ListViewSelectedIndexChanged(object sender, EventArgs e) { if (this.listView1.FocusedItem != null && this.listView1.FocusedItem.Selected) { if (AppWorkspace.toInitImageIndexDialogFlag != 1) { AppWorkspace.toInitImageIndexDialogFlag = 2; AppWorkspace.ActiveDocumentWorkspace = AppWorkspace.DocumentWorkspaces[AppWorkspace.DocumentWorkspaces.Length - 1 - this.listView1.FocusedItem.Index]; } this.imageMat = AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreateAliasedBitmap(); isFirst = true; lastPoint.X = 0; lastPoint.Y = 0; refreshSizeMode(); } } /// /// 初始化图片列表数据 /// public void InitData() {//需要优化调用的时机,隐藏时切换图片不需要切换,显示时显示图片。并且隐藏时置为null,显示时读取当前mat。 //return; this.imageList1.Images.Clear(); this.listView1.Items.Clear(); this.listView1.Columns.Clear(); //this.pictureBox1.Image = null; if (AppWorkspace.DocumentWorkspaces.Length == 0 || AppWorkspace.ActiveDocumentWorkspace == null) { this.listView1.Refresh(); this.pictureBox1.Image = null; return; } int typeLenth = 70; int nameLenth = 100; if (this.listView1.Width > 310) { typeLenth = this.listView1.Width / 5; nameLenth = this.listView1.Width * 2 / 5; if (typeLenth > 70) { typeLenth = 70; nameLenth = this.listView1.Width - 215; } } ColumnHeader header = new ColumnHeader(); header.Text = PdnResources.GetString("Menu.File.Text"); header.Width = nameLenth; this.listView1.Columns.Add(header); header = new ColumnHeader(); header.Text = PdnResources.GetString("Menu.Type.text"); header.Width = typeLenth; this.listView1.Columns.Add(header); header = new ColumnHeader(); header.Text = PdnResources.GetString("Menu.size.text"); header.Width = typeLenth; this.listView1.Columns.Add(header); header = new ColumnHeader(); header.Text = PdnResources.GetString("MeasurementUnit.Pixel"); header.Width = typeLenth; this.listView1.Columns.Add(header); this.imageList1.ImageSize = new Size(this.listView1.Width - 91 > 250 ? 250 : this.listView1.Width - 91, this.listView1.Width - 91 > 250 ? 250 : this.listView1.Width - 91); //初始化图片列表 for (int i = 0; i < AppWorkspace.DocumentWorkspaces.Length; i++) { DocumentWorkspace iDocumentWorkspace = AppWorkspace.DocumentWorkspaces[AppWorkspace.DocumentWorkspaces.Length - 1 - i]; //added begin by songxk //added end by songxk this.imageList1.Images.Add("img" + i, OpenCvSharp.Extensions.BitmapConverter.ToBitmap(iDocumentWorkspace.BoxMat)); this.listView1.Items.Add("", i); this.listView1.Items[i].ImageIndex = i; this.listView1.Items[i].Text = iDocumentWorkspace.GetFriendlyName(); this.listView1.Items[i].Name = iDocumentWorkspace.GetFriendlyName(); string type = ""; if (iDocumentWorkspace.GetFriendlyName().IndexOf('.') > -1) { type = iDocumentWorkspace.GetFriendlyName().Substring(iDocumentWorkspace.GetFriendlyName().LastIndexOf('.') + 1, iDocumentWorkspace.GetFriendlyName().Length - iDocumentWorkspace.GetFriendlyName().LastIndexOf('.') - 1); } else { type = ""; } this.imageMat = iDocumentWorkspace.CompositionSurface.CreateAliasedBitmap(); //图片类型 this.listView1.Items[i].SubItems.Add(type); //获取图片路径 string fileName; //FileType fileType; //SaveConfigToken saveConfigToken; iDocumentWorkspace.GetDocumentSaveOptions(out fileName/*, out fileType, out saveConfigToken*/); //获取图片信息 if (fileName != null) { //获取图片对应xml PicConfigModel configModel = null; try { string path = Path.GetDirectoryName(fileName); string xmlPath = path + "\\" + Path.GetFileNameWithoutExtension(fileName) + ".xml"; //如果xml存在 if (System.IO.File.Exists(xmlPath)) { configModel = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(xmlPath, FileMode.Open)); if (configModel != null) { //图片大小 this.listView1.Items[i].SubItems.Add(configModel.meta.imageSize); } } else { //获取图片信息 if (System.IO.File.Exists(fileName)) { FileInfo fi = new FileInfo(fileName); //图片大小 this.listView1.Items[i].SubItems.Add(FileOperationHelper.GetLength(fi.Length)); } } } catch (Exception) { } } else { //图像若没有信息像素计算 double length = imageMat.Width * imageMat.Height; double lengthKb = length * 24 /8 / 1024 / 4.77; double lengthMb = length * 24/ 8 / 1024 / 1024 / 4.77; if (lengthKb >= 1024) { this.listView1.Items[i].SubItems.Add(lengthMb.ToString("f2") + "M"); } else { this.listView1.Items[i].SubItems.Add(lengthKb.ToString("f0") + "KB"); } } //图片像素 this.listView1.Items[i].SubItems.Add(imageMat.Width.ToString() + "*" + imageMat.Height.ToString()); } if (index != -1) { this.listView1.Items[index].Focused = true; this.listView1.Items[index].Selected = true; } else { if (this.listView1.Items.Count > 0 && AppWorkspace.DocumentWorkspaces.Length > 0 && AppWorkspace.ActiveDocumentWorkspace != null) { this.listView1.Items[0].Focused = true; this.listView1.Items[0].Selected = true; } } } /// /// 根据图片尺寸判断picturebox的显示模式并刷新图片 /// private void refreshSizeMode() { if (imageMat != null) { if (imageMat.Width > pictureBox1.Size.Width || imageMat.Height > pictureBox1.Size.Height) { pictureBox1.SizeMode = PictureBoxSizeMode.Zoom; } else { pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage; } this.pictureBox1.Image = imageMat; } } /// /// 窗体尺寸改变 /// /// /// private void ImageIndexDialog_Resize(object sender, EventArgs e) { lastPoint.X = 0; lastPoint.Y = 0; isFirst = true; refreshSizeMode(); } /// /// 绘制picturebox /// /// /// private void pictureBox1_Paint(object sender, PaintEventArgs e) { if (this.pictureBox1.Image != null) { if (isFirst) { //获取缩略图对应矩形 PropertyInfo _ImageRectanglePropert = this.pictureBox1.GetType().GetProperty("ImageRectangle", BindingFlags.Instance | BindingFlags.NonPublic); imageRect = (Rectangle)_ImageRectanglePropert.GetValue(this.pictureBox1, null); Size size = AppWorkspace.ActiveDocumentWorkspace.panel.ClientSize;//document窗体尺寸 double ratio = AppWorkspace.ActiveDocumentWorkspace.ScaleRatio; if (size.Width < this.imageMat.Width * ratio) widthRatio = size.Width / (this.imageMat.Width * ratio); else widthRatio = 1; if (size.Height < this.imageMat.Height * ratio) heightRatio = size.Height / (this.imageMat.Height * ratio); else heightRatio = 1; Point scPoint = AppWorkspace.ActiveDocumentWorkspace.PanelScrollPosition;//当前滚动条位置 scRatioWidth = imageRect.Width / (imageMat.Width * ratio); scRatioHeight = imageRect.Height / (imageMat.Height * ratio); //缩略图中红框选中区域 zoomRect = new Rectangle(imageRect.X + (int)(scPoint.X * scRatioWidth), imageRect.Y + (int)(scPoint.Y * scRatioHeight), (int)(imageRect.Width * widthRatio), (int)(imageRect.Height * heightRatio)); //红框矩形的最小尺寸,即原图放大3200% double minWidthRatio = size.Width / (this.imageMat.Width * 32d); double minHeightRatio = size.Height / (this.imageMat.Height * 32d); minRectWidth = (int)(Math.Round(imageRect.Width * minWidthRatio)); minRectHeight = (int)(Math.Round(imageRect.Height * minHeightRatio)); } e.Graphics.DrawRectangle(new Pen(Color.Red), zoomRect.X, zoomRect.Y, zoomRect.Width - 1, zoomRect.Height - 1); e.Graphics.FillRectangle(new SolidBrush(Color.Black), new Rectangle(zoomRect.Right - 5, zoomRect.Bottom - 5, 9, 9)); } } /// /// picturebox的鼠标按下事件 /// /// /// private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { lastPoint.X = e.X; lastPoint.Y = e.Y; //是否平移 if (zoomRect.Contains(e.Location) && !new Rectangle(zoomRect.Right - 5, zoomRect.Bottom - 5, 9, 9).Contains(e.Location)) isMoved = true; else isMoved = false; //是否放大缩小 if (new Rectangle(zoomRect.Right - 5, zoomRect.Bottom - 5, 9, 9).Contains(e.Location)) isResized = true; else isResized = false; } /// /// pocturebox的鼠标移动事件 /// /// /// private void pictureBox1_MouseMove(object sender, MouseEventArgs e) { //修改鼠标形状 this.pictureBox1.Cursor = Cursors.Default; if (zoomRect != null) { if (zoomRect.Contains(e.Location) && !new Rectangle(zoomRect.Right - 5, zoomRect.Bottom - 5, 9, 9).Contains(e.Location)) { this.pictureBox1.Cursor = Cursors.SizeAll; } if (new Rectangle(zoomRect.Right - 4, zoomRect.Bottom - 4, 7, 7).Contains(e.Location)) { this.pictureBox1.Cursor = Cursors.SizeNWSE; } } if (e.Button != MouseButtons.Left) return; //拖拽 if (zoomRect != null && isMoved) { isFirst = false; Point p = e.Location; int dx = p.X - lastPoint.X; int dy = p.Y - lastPoint.Y; lastPoint.X = p.X; lastPoint.Y = p.Y; zoomRect.X += dx; zoomRect.Y += dy; //控制矩形框不超过缩略图尺寸 int xc = (this.pictureBox1.Width - this.imageRect.Width) / 2; int yc = (this.pictureBox1.Height - this.imageRect.Height) / 2; if (zoomRect.X < xc) zoomRect.X = xc; if (zoomRect.Y < yc) zoomRect.Y = yc; if (zoomRect.X + zoomRect.Width > imageRect.Width + xc) zoomRect.X = imageRect.Width - zoomRect.Width + xc; if (zoomRect.Y + zoomRect.Height > imageRect.Height + yc) zoomRect.Y = imageRect.Height - zoomRect.Height + yc; this.pictureBox1.Refresh(); //修改document的滚动条 Point scPoint = AppWorkspace.ActiveDocumentWorkspace.PanelScrollPosition; double scrollDx = dx / scRatioWidth; double scrollDy = dy / scRatioHeight; Point newScPoint = new Point(scPoint.X + Convert.ToInt32(Math.Round(scrollDx)), scPoint.Y + Convert.ToInt32(Math.Round(scrollDy))); AppWorkspace.ActiveDocumentWorkspace.PanelScrollPosition = newScPoint; } //缩放 if (zoomRect != null && isResized) { isFirst = false; Point p = e.Location; int dx = p.X - lastPoint.X; int dy = p.Y - lastPoint.Y; lastPoint.X = p.X; lastPoint.Y = p.Y; //偏移量取横坐标与纵坐标中绝对值大的 int delta = dx; if (Math.Abs(dy) > Math.Abs(dx)) delta = dy; Size size = AppWorkspace.ActiveDocumentWorkspace.panel.ClientSize;//document尺寸 double ratio = AppWorkspace.ActiveDocumentWorkspace.ScaleRatio;//缩放比 //图片缩放后的宽和高都小于document窗口尺寸 if (size.Width > this.imageMat.Width * ratio && size.Height > this.imageMat.Height * ratio) { AppWorkspace.ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;//修改缩放模式 //只修改缩放比,不改变缩略图矩形框尺寸 ratio += (-delta / 100d); ratio = GetMinRatio(ratio); RefreshActiveDocumentScaleFactor(ratio); } //图片缩放后的宽和高大于等于doucment窗口尺寸 else { double aspectRatio = size.Width / (size.Height * 1d);//宽高比 int maxResizedWidth = imageRect.Right - zoomRect.Right;//正向最大拖动宽度 int maxResizedHeigth = imageRect.Bottom - zoomRect.Bottom;//正向最大拖动高度 int maxRectWidth = maxResizedWidth + zoomRect.Width;//小矩形可放大到的最大宽度 int maxRectHeight = maxResizedHeigth + zoomRect.Height;//小矩形可放大到的最大高度 double newScaleRatio = 0;//计算后新的缩放比 double newScPointX = 0;//计算后新的滚动条横坐标 double newScPointY = 0;//计算后新的滚动条纵坐标 //图片缩放后只有宽小于ducument窗口尺寸 if (size.Width > this.imageMat.Width * ratio && size.Height <= this.imageMat.Height * ratio) { int minHeight = (int)Math.Round(imageRect.Width / aspectRatio);//矩形框可拖动的最小高度 zoomRect.Height += delta; if (zoomRect.Height > maxRectHeight) { zoomRect.Height = maxRectHeight; //矩形框的起始点不在缩略图的起始点上时,高度达到默认可变的最大值后,同时修改纵坐标和高度 if (maxRectHeight < imageRect.Height) { zoomRect.Y -= delta; if (zoomRect.Y < imageRect.Y) zoomRect.Y = imageRect.Y; zoomRect.Height += delta; if (zoomRect.Height > imageRect.Height) zoomRect.Height = imageRect.Height; this.pictureBox1.Refresh(); newScaleRatio = Math.Round(size.Height / heightRatio / this.imageMat.Height, 2);//重新计算缩放比 newScaleRatio = GetMinRatio(newScaleRatio); //重新计算滚轮所需比例 scRatioWidth = imageRect.Width / (imageMat.Width * newScaleRatio); scRatioHeight = imageRect.Height / (imageMat.Height * newScaleRatio); //重新计算document的滚动条横坐标与纵坐标 newScPointX = (zoomRect.X - imageRect.X) / scRatioWidth; newScPointY = (zoomRect.Y - imageRect.Y) / scRatioHeight; RefreshActiveDocumentScaleFactorAndScroll(ratio, new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY))); return; } //高度达到极限,只改变缩放比 this.pictureBox1.Refresh(); ratio += (-delta / 100d); ratio = GetMinRatio(ratio); RefreshActiveDocumentScaleFactor(ratio); return; } if (zoomRect.Height < minHeight) zoomRect.Height = minHeight; this.pictureBox1.Refresh(); heightRatio = zoomRect.Height / (imageRect.Height * 1d); heightRatio = GetMaxDocumentWithBitmapRatio(heightRatio); newScaleRatio = Math.Round(size.Height / heightRatio / this.imageMat.Height, 2);//重新计算缩放比 } //图片缩放后只有高小于ducument窗口尺寸 if (size.Width <= this.imageMat.Width * ratio && size.Height > this.imageMat.Height * ratio) { int minWidth = (int)Math.Round(imageRect.Height * aspectRatio);//矩形框可拖动的最小宽度 zoomRect.Width += delta; if (zoomRect.Width > maxRectWidth) { zoomRect.Width = maxRectWidth; //矩形框的起始点不在缩略图的起始点上时,宽度达到默认可变的最大值后,同时修改横坐标和宽度 if (maxRectWidth < imageRect.Width) { zoomRect.X -= delta; if (zoomRect.X < imageRect.X) zoomRect.X = imageRect.X; zoomRect.Width += delta; if (zoomRect.Width > imageRect.Width) zoomRect.Width = imageRect.Width; this.pictureBox1.Refresh(); newScaleRatio = Math.Round(size.Width / widthRatio / this.imageMat.Width, 2);//重新计算缩放比 newScaleRatio = GetMinRatio(newScaleRatio); //重新计算滚轮所需比例 scRatioWidth = imageRect.Width / (imageMat.Width * newScaleRatio); scRatioHeight = imageRect.Height / (imageMat.Height * newScaleRatio); //重新计算document的滚动条横坐标与纵坐标 newScPointX = (zoomRect.X - imageRect.X) / scRatioWidth; newScPointY = (zoomRect.Y - imageRect.Y) / scRatioHeight; RefreshActiveDocumentScaleFactorAndScroll(newScaleRatio, new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY))); return; } //宽度达到极限,改变缩放比 this.pictureBox1.Refresh(); ratio += (-delta / 100d); ratio = GetMinRatio(ratio); RefreshActiveDocumentScaleFactor(ratio); return; } if (zoomRect.Width < minWidth) zoomRect.Width = minWidth; this.pictureBox1.Refresh(); widthRatio = zoomRect.Width / (imageRect.Width * 1d); widthRatio = GetMaxDocumentWithBitmapRatio(widthRatio); newScaleRatio = Math.Round(size.Width / widthRatio / this.imageMat.Width, 2);//重新计算缩放比 } //图片缩放后的宽和高都不小于document窗体尺寸 if (size.Width <= this.imageMat.Width * ratio && size.Height <= this.imageMat.Height * ratio) { if (maxResizedWidth < maxResizedHeigth) { zoomRect.Width += delta; if (zoomRect.Width > maxRectWidth) { zoomRect.Width = maxRectWidth; //矩形框的宽度与缩略图宽度相同时才可改变高度并调整缩放比 if(zoomRect.Width >= imageRect.Width) { zoomRect.Height += delta; this.pictureBox1.Refresh(); heightRatio = zoomRect.Height / (imageRect.Height * 1d); heightRatio = GetMaxDocumentWithBitmapRatio(heightRatio); newScaleRatio = Math.Round(size.Height / heightRatio / this.imageMat.Height, 2);//重新计算缩放比 newScaleRatio = GetMinRatio(newScaleRatio); //重新计算滚轮所需比例 scRatioWidth = imageRect.Width / (imageMat.Width * newScaleRatio); scRatioHeight = imageRect.Height / (imageMat.Height * newScaleRatio); //重新计算document的滚动条横坐标与纵坐标 newScPointX = (zoomRect.X - imageRect.X) / scRatioWidth; newScPointY = (zoomRect.Y - imageRect.Y) / scRatioHeight; RefreshActiveDocumentScaleFactorAndScroll(newScaleRatio, new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY))); return; } } if (zoomRect.Width < minRectWidth) zoomRect.Width = minRectWidth; zoomRect.Height = (int)Math.Round(zoomRect.Width / aspectRatio); } else { zoomRect.Height += delta; if (zoomRect.Height > maxRectHeight) { zoomRect.Height = maxRectHeight; //矩形框的高度与缩略图高度相同时才可改变宽度并调整缩放比 if (zoomRect.Height >= imageRect.Height) { zoomRect.Width += delta; this.pictureBox1.Refresh(); widthRatio = zoomRect.Width / (imageRect.Width * 1d); widthRatio = GetMaxDocumentWithBitmapRatio(widthRatio); newScaleRatio = Math.Round(size.Width / widthRatio / this.imageMat.Width, 2);//重新计算缩放比 newScaleRatio = GetMinRatio(newScaleRatio); //重新计算滚轮所需比例 scRatioWidth = imageRect.Width / (imageMat.Width * newScaleRatio); scRatioHeight = imageRect.Height / (imageMat.Height * newScaleRatio); //重新计算document的滚动条横坐标与纵坐标 newScPointX = (zoomRect.X - imageRect.X) / scRatioWidth; newScPointY = (zoomRect.Y - imageRect.Y) / scRatioHeight; RefreshActiveDocumentScaleFactorAndScroll(newScaleRatio, new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY))); return; } } if (zoomRect.Height < minRectHeight) zoomRect.Height = minRectHeight; zoomRect.Width = (int)Math.Round(zoomRect.Height * aspectRatio); } this.pictureBox1.Refresh(); //重新计算比例 widthRatio = zoomRect.Width / (imageRect.Width * 1d); widthRatio = GetMaxDocumentWithBitmapRatio(widthRatio); heightRatio = zoomRect.Height / (imageRect.Height * 1d); heightRatio = GetMaxDocumentWithBitmapRatio(heightRatio); //计算document的缩放比,宽和高的计算结果会有细微差异 double scaleW = Math.Round(size.Width / widthRatio / this.imageMat.Width, 2); double scaleH = Math.Round(size.Height / heightRatio / this.imageMat.Height, 2); //取大的值作为新的缩放比?不确定 if (scaleW >= scaleH) newScaleRatio = scaleW; else newScaleRatio = scaleH; } //重新计算滚轮所需比例 scRatioWidth = imageRect.Width / (imageMat.Width * newScaleRatio); scRatioHeight = imageRect.Height / (imageMat.Height * newScaleRatio); //重新计算document的滚动条横坐标与纵坐标 newScPointX = (zoomRect.X - imageRect.X) / scRatioWidth; newScPointY = (zoomRect.Y - imageRect.Y) / scRatioHeight; RefreshActiveDocumentScaleFactorAndScroll(newScaleRatio, new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY))); } } } /// /// 控制缩放比的最小值为1% /// /// /// private double GetMinRatio(double ratio) { if (ratio < 0.01) ratio = 0.01; return ratio; } /// /// 控制document窗口与缩放后图片比例,最大值为1 /// /// /// private double GetMaxDocumentWithBitmapRatio(double ratio) { if (ratio > 1) ratio = 1; return ratio; } /// /// 刷新当前激活document的缩放比 /// /// /// private bool RefreshActiveDocumentScaleFactor(double scaleRatio) { AppWorkspace.ActiveDocumentWorkspace.ScaleFactor = ScaleFactor.FromDouble(scaleRatio); AppWorkspace.ActiveDocumentWorkspace.Refresh(); return true; } /// /// 刷新当前激活document的缩放比与滚动条 /// /// /// private bool RefreshActiveDocumentScaleFactorAndScroll(double scaleRatio, Point point) { AppWorkspace.ActiveDocumentWorkspace.ScaleFactor = ScaleFactor.FromDouble(scaleRatio); AppWorkspace.ActiveDocumentWorkspace.PanelScrollPosition = point; AppWorkspace.ActiveDocumentWorkspace.Refresh(); return true; } private void button7_Click(object sender, EventArgs e) { if (this.listView1.View == View.Details) return; for (int i = 0; i < this.listView1.Items.Count; i++) { if (AppWorkspace.DocumentWorkspaces[i].GetFriendlyName().IndexOf('.') > -1) { this.listView1.Items[i].Text = AppWorkspace.DocumentWorkspaces[i].GetFriendlyName().Substring(0, AppWorkspace.DocumentWorkspaces[i].GetFriendlyName().LastIndexOf('.')); this.listView1.Items[i].Name = AppWorkspace.DocumentWorkspaces[i].GetFriendlyName().Substring(0, AppWorkspace.DocumentWorkspaces[i].GetFriendlyName().LastIndexOf('.')); } else { this.listView1.Items[i].Text = AppWorkspace.DocumentWorkspaces[i].GetFriendlyName(); this.listView1.Items[i].Name = AppWorkspace.DocumentWorkspaces[i].GetFriendlyName(); } } //string ssss = "333.44.555.666.jpg"; //int n = ssss.LastIndexOf("."); //InitData(); this.listView1.View = View.Details; } private void button8_Click(object sender, EventArgs e) { if (this.listView1.View == View.LargeIcon) return; ////初始化图片列表 //for (int i = 0; i < this.listView1.Items.Count; i++) //{ // this.listView1.Items[i].Text = AppWorkspace.DocumentWorkspaces[i].GetFriendlyName(); // this.listView1.Items[i].Name = AppWorkspace.DocumentWorkspaces[i].GetFriendlyName(); //} this.imageList1.ImageSize = new Size(this.listView1.Width-91 > 250? 250: this.listView1.Width-91, this.listView1.Width-91 > 250 ? 250 : this.listView1.Width-91); //InitData(); this.listView1.View = View.LargeIcon; } /// /// 折叠展开 /// /// /// private void btn_Hide_Click(object sender, EventArgs e) { if (btn_Hide.Text == ">>" && this.fromMinSize == this.fromMaxSize) { this.fromMaxSize = fixedWidth; } if (this.Width == this.fromMinSize) { btn_Hide.Text = "<<"; this.MaximumSize = new Size(0,0); this.Width = this.fromMaxSize; } else { btn_Hide.Text = ">>"; this.fromMaxSize = this.Width; this.fromMinSize = splitContainer1.SplitterDistance +24; this.Width = this.fromMinSize; this.MaximumSize = new Size(400, this.Height); //this.fromMinSize = this.Width; } } /// /// 配合折叠展开 /// /// /// private void ImageIndexDialog_SizeChanged(object sender, EventArgs e) { if (this.btn_Hide.Text == ">>") { splitContainer1.IsSplitterFixed = true; splitContainer1.FixedPanel = FixedPanel.Panel1; if (this.Width >= this.fromMaxSize) { panel1.Width = this.Width + extendWidth; this.fromMaxSize = this.Width + extendWidth +24; } //if (this.Width <= this.fromMinSize) //{ // panel1.Width = this.Width + 550; // this.fromMaxSize = this.Width + 574; //} splitContainer1.SplitterDistance = this.Width - 24; this.fromMinSize = this.Width; return; } if (this.btn_Hide.Text == "<<") { splitContainer1.IsSplitterFixed = false; splitContainer1.FixedPanel = FixedPanel.None; splitContainer1.SplitterDistance = this.fromMinSize - 24; this.fromMaxSize = this.Width; } if (this.Width > this.fromMinSize) { this.btn_Hide.Text = "<<"; if (this.MaximumSize.Width == 400) this.MaximumSize = new Size(0, 0); } else { this.btn_Hide.Text = ">>"; if (this.MaximumSize.Width != 400) this.MaximumSize = new Size(400, this.Height); } if (this.Width - 24 > panel1.Width || btn_Hide.Text == "<<" || this.Width > this.fromMinSize) panel1.Width = this.Width - 24; //if (this.btn_Hide.Text == ">>") //{ // splitContainer1.IsSplitterFixed = true; // splitContainer1.FixedPanel = FixedPanel.Panel1; // //splitContainer1.SplitterDistance = this.Width - 24; //} //else //{ // splitContainer1.IsSplitterFixed = false; // splitContainer1.FixedPanel = FixedPanel.None; //} } private void panel1_SizeChanged(object sender, EventArgs e) { splitContainer1.SplitterDistance = this.fromMinSize - 24; } private int index =-1; private void splitContainer1_Panel1_SizeChanged(object sender, EventArgs e) { if (this.fromMinSize != splitContainer1.SplitterDistance + 24) { this.fromMinSize = splitContainer1.SplitterDistance + 24; if (this.listView1.FocusedItem != null) { index = this.listView1.FocusedItem.Index; InitData(); index = -1; } } if (splitContainer1.SplitterDistance > 376) { splitContainer1.SplitterDistance = 376; } lblPreview.Width = splitContainer1.SplitterDistance - 22; } private void button10_Click(object sender, EventArgs e) { using (BatchSaveDialog dialog = new BatchSaveDialog(AppWorkspace)) { if (AppWorkspace.startScriptRecording) { AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List()); } dialog.StartPosition = FormStartPosition.CenterScreen; dialog.ShowDialog(); } } /// /// 命名规则设置 /// /// /// private void btn_SetUp_Click(object sender, EventArgs e) { if (AppWorkspace.startScriptRecording) { AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List()); } using (GeneralSettingDialog af = new GeneralSettingDialog(AppWorkspace)) { af.groupBox1.Visible = false; af.groupBox2.Location = new Point(6,13); af.groupBox5.Location = new Point(6, 136); af.groupBox19.Location = new Point(6, 74); af.Width = af.Width - af.groupBox1.Width; af.StartPosition = FormStartPosition.CenterScreen; af.ShowDialog(AppWorkspace); } } public void PreviewRefresh(int mode = 0) { config.Txt1 = comboBox_T1.Text; config.Txt2 = comboBox_T2.Text; config.Txt3 = comboBox_T2.Text; string photoName; if (Startup.instance.ruleDB == null) photoName = NamingRuleHelper.GetNameFromXml(Startup.instance.configModel, "默认标尺", "0", mode); else photoName = NamingRuleHelper.GetNameFromXml(Startup.instance.configModel, Startup.instance.ruleDB.ruler_name, Startup.instance.ruleDB.gain_multiple.ToString(), mode); lblPreview.Text = photoName; } private void comboBox_T1_TextUpdate(object sender, EventArgs e) { PreviewRefresh(config.CaptureSaveMode); } private void comboBox_T2_TextUpdate(object sender, EventArgs e) { PreviewRefresh(config.CaptureSaveMode); } private void comboBox_T3_TextUpdate(object sender, EventArgs e) { PreviewRefresh(config.CaptureSaveMode); } /// /// 刷新条目名称 /// public void comboBox_Name_Refresh(int mode = 0) { this.comboBox_Name.SelectedIndexChanged -= new System.EventHandler(this.comboBox_Name_SelectedIndexChanged); string[] lstName = config.LstNaming.Select(a => a.name).ToArray(); this.comboBox_Name.DataSource = lstName; this.comboBox_Name.Text = config.CurrentName; this.comboBox_Name.SelectedIndexChanged += new System.EventHandler(this.comboBox_Name_SelectedIndexChanged); PreviewRefresh(mode); } /// /// 添加自定义文本1 /// /// /// private void btn_AddT1_Click(object sender, EventArgs e) { if (comboBox_T1.Text.Trim() == "") { MessageBox.Show("参数不能为空!"); return; }; CurrentLocation = 1; CustomTxt customTxt = new CustomTxt(); customTxt.customT = comboBox_T1.Text.Trim(); if (config.LstCustomTxt == null) config.LstCustomTxt = new CustomTxtModel(); if (config.LstCustomTxt.customTxts1 == null) config.LstCustomTxt.customTxts1 = new List(); if (Inspect()) { MessageBox.Show("名称重复!"); return; } config.LstCustomTxt.customTxts1.Add(customTxt); config.Txt1 = comboBox_T1.Text.Trim(); string configXml = XmlSerializeHelper.XmlSerialize(config); string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml"; if (!FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create)) MessageBox.Show(PdnResources.GetString("Menu.mingconventionsavefailed.text")); if (config.LstCustomTxt.customTxts1 != null && config.LstCustomTxt.customTxts1.Count > 0) { string[] lstName = config.LstCustomTxt.customTxts1.Select(a => a.customT).ToArray(); this.comboBox_T1.DataSource = lstName; if (lstName.Length > 0) this.comboBox_T1.Text = customTxt.customT; } else this.comboBox_T1.DataSource = null; } /// /// 添加自定义文本2 /// /// /// private void btn_AddT2_Click(object sender, EventArgs e) { if (comboBox_T2.Text.Trim() == "") { MessageBox.Show("参数不能为空!"); return; }; CurrentLocation = 2; CustomTxt customTxt = new CustomTxt(); customTxt.customT = comboBox_T2.Text.Trim(); if (config.LstCustomTxt == null) config.LstCustomTxt = new CustomTxtModel(); if (config.LstCustomTxt.customTxts2 == null) config.LstCustomTxt.customTxts2 = new List(); if (Inspect()) { MessageBox.Show("名称重复!"); return; } config.LstCustomTxt.customTxts2.Add(customTxt); config.Txt2 = comboBox_T2.Text.Trim(); string configXml = XmlSerializeHelper.XmlSerialize(config); string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml"; if (!FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create)) MessageBox.Show(PdnResources.GetString("Menu.mingconventionsavefailed.text")); if (config.LstCustomTxt.customTxts2 != null && config.LstCustomTxt.customTxts2.Count > 0) { string[] lstName = config.LstCustomTxt.customTxts2.Select(a => a.customT).ToArray(); this.comboBox_T2.DataSource = lstName; if (lstName.Length > 0) this.comboBox_T2.Text = customTxt.customT; } else this.comboBox_T2.DataSource = null; } private void TxtAssignment() { config.Txt1 = comboBox_T1.Text.Trim(); config.Txt2 = comboBox_T2.Text.Trim(); config.Txt3 = comboBox_T3.Text.Trim(); string configXml = XmlSerializeHelper.XmlSerialize(config); string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml"; if (!FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create)) MessageBox.Show(PdnResources.GetString("Menu.mingconventionsavefailed.text")); } /// /// 添加自定义文本3 /// /// /// private void btn_AddT3_Click(object sender, EventArgs e) { if (comboBox_T3.Text.Trim() == "") { MessageBox.Show("参数不能为空!"); return; }; CurrentLocation = 3; CustomTxt customTxt = new CustomTxt(); customTxt.customT = comboBox_T3.Text.Trim(); if (config.LstCustomTxt == null) config.LstCustomTxt = new CustomTxtModel(); if (config.LstCustomTxt.customTxts3 == null) config.LstCustomTxt.customTxts3 = new List(); if (Inspect()) { MessageBox.Show("名称重复!"); return; } config.LstCustomTxt.customTxts3.Add(customTxt); config.Txt3 = comboBox_T3.Text.Trim(); string configXml = XmlSerializeHelper.XmlSerialize(config); string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml"; if (!FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create)) MessageBox.Show(PdnResources.GetString("Menu.mingconventionsavefailed.text")); if (config.LstCustomTxt.customTxts3 != null && config.LstCustomTxt.customTxts3.Count > 0) { string[] lstName = config.LstCustomTxt.customTxts3.Select(a => a.customT).ToArray(); this.comboBox_T3.DataSource = lstName; if (lstName.Length > 0) this.comboBox_T3.Text = customTxt.customT; } else this.comboBox_T3.DataSource = null; } //文本检查 private bool Inspect() { bool chek = false; string name = string.Empty; switch (CurrentLocation) { case 1: name = comboBox_T1.Text.Trim(); if (config.LstCustomTxt.customTxts1.Count > 0) { string[] lstName = config.LstCustomTxt.customTxts1.Select(a => a.customT).ToArray(); chek = ((IList)lstName).Contains(name); } break; case 2: name = comboBox_T2.Text.Trim(); if (config.LstCustomTxt.customTxts2.Count > 0) { string[] lstName = config.LstCustomTxt.customTxts2.Select(a => a.customT).ToArray(); chek = ((IList)lstName).Contains(name); } break; case 3: name = comboBox_T3.Text.Trim(); if (config.LstCustomTxt.customTxts3.Count > 0) { string[] lstName = config.LstCustomTxt.customTxts3.Select(a => a.customT).ToArray(); chek = ((IList)lstName).Contains(name); } break; default: break; } CurrentLocation = -1; return chek; } /// /// 初始化 /// public void NamingInitialization() { if (config.LstCustomTxt != null ) { if (config.LstCustomTxt.customTxts1 != null && config.LstCustomTxt.customTxts1.Count > 0) { string[] lstName = config.LstCustomTxt.customTxts1.Select(a => a.customT).ToArray(); this.comboBox_T1.DataSource = lstName; if (lstName.Length > 0) this.comboBox_T1.Text = config.Txt1; } else this.comboBox_T1.DataSource = null; if (config.LstCustomTxt.customTxts2 != null && config.LstCustomTxt.customTxts2.Count > 0) { string[] lstName = config.LstCustomTxt.customTxts2.Select(a => a.customT).ToArray(); this.comboBox_T2.DataSource = lstName; if (lstName.Length > 0) this.comboBox_T2.Text = config.Txt2; } else this.comboBox_T2.DataSource = null; if (config.LstCustomTxt.customTxts3 != null && config.LstCustomTxt.customTxts3.Count > 0) { string[] lstName = config.LstCustomTxt.customTxts3.Select(a => a.customT).ToArray(); this.comboBox_T3.DataSource = lstName; if (lstName.Length > 0) this.comboBox_T3.Text = config.Txt3; } else this.comboBox_T3.DataSource = null; } this.comboBox_T1.SelectedIndexChanged += new System.EventHandler(this.comboBox_T1_SelectedIndexChanged); this.comboBox_T2.SelectedIndexChanged += new System.EventHandler(this.comboBox_T2_SelectedIndexChanged); this.comboBox_T3.SelectedIndexChanged += new System.EventHandler(this.comboBox_T3_SelectedIndexChanged); } private void btn_DelT1_Click(object sender, EventArgs e) { if (comboBox_T1.Text.Trim() == "") { MessageBox.Show("参数不能为空!"); return; }; DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Areyousuretcteddata.text") + "?", PdnResources.GetString("Menu.ensure.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); if (dr == DialogResult.Cancel) return; CurrentLocation = 1; if (config.LstCustomTxt == null || config.LstCustomTxt.customTxts1 == null || !Inspect()) { MessageBox.Show("不存在此文本!"); return; } for (int i = 0; i < config.LstCustomTxt.customTxts1.Count; i++) { if (comboBox_T1.Text.Trim().Equals(config.LstCustomTxt.customTxts1[i].customT)) config.LstCustomTxt.customTxts1.Remove(config.LstCustomTxt.customTxts1[i]); } string configXml = XmlSerializeHelper.XmlSerialize(config); string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml"; if (!FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create)) MessageBox.Show(PdnResources.GetString("Menu.mingconventionsavefailed.text")); if (config.LstCustomTxt.customTxts1 != null && config.LstCustomTxt.customTxts1.Count > 0) { string[] lstName = config.LstCustomTxt.customTxts1.Select(a => a.customT).ToArray(); this.comboBox_T1.DataSource = lstName; } else this.comboBox_T1.DataSource = null; } private void btn_DelT2_Click(object sender, EventArgs e) { if (comboBox_T2.Text.Trim() == "") { MessageBox.Show("参数不能为空!"); return; }; DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Areyousuretcteddata.text") + "?", PdnResources.GetString("Menu.ensure.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); if (dr == DialogResult.Cancel) return; CurrentLocation = 2; if (config.LstCustomTxt == null || config.LstCustomTxt.customTxts2 == null || !Inspect()) { MessageBox.Show("不存在此文本!"); return; } for (int i = 0; i < config.LstCustomTxt.customTxts2.Count; i++) { if (comboBox_T2.Text.Trim().Equals(config.LstCustomTxt.customTxts2[i].customT)) config.LstCustomTxt.customTxts2.Remove(config.LstCustomTxt.customTxts2[i]); } string configXml = XmlSerializeHelper.XmlSerialize(config); string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml"; if (!FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create)) MessageBox.Show(PdnResources.GetString("Menu.mingconventionsavefailed.text")); if (config.LstCustomTxt.customTxts2 != null && config.LstCustomTxt.customTxts2.Count > 0) { string[] lstName = config.LstCustomTxt.customTxts2.Select(a => a.customT).ToArray(); this.comboBox_T2.DataSource = lstName; } else this.comboBox_T2.DataSource = null; } private void btn_DelT3_Click(object sender, EventArgs e) { if (comboBox_T3.Text.Trim() == "") { MessageBox.Show("参数不能为空!"); return; }; DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.Areyousuretcteddata.text") + "?", PdnResources.GetString("Menu.ensure.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); if (dr == DialogResult.Cancel) return; CurrentLocation = 3; if (config.LstCustomTxt == null || config.LstCustomTxt.customTxts3 == null || !Inspect()) { MessageBox.Show("不存在此文本!"); return; } for (int i = 0; i < config.LstCustomTxt.customTxts3.Count; i++) { if (comboBox_T3.Text.Trim().Equals(config.LstCustomTxt.customTxts3[i].customT)) config.LstCustomTxt.customTxts3.Remove(config.LstCustomTxt.customTxts3[i]); } string configXml = XmlSerializeHelper.XmlSerialize(config); string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml"; if (!FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create)) MessageBox.Show(PdnResources.GetString("Menu.mingconventionsavefailed.text")); if (config.LstCustomTxt.customTxts3 != null && config.LstCustomTxt.customTxts3.Count > 0) { string[] lstName = config.LstCustomTxt.customTxts3.Select(a => a.customT).ToArray(); this.comboBox_T3.DataSource = lstName; } else this.comboBox_T3.DataSource = null; } /// /// 鼠标事件-右键 /// /// /// private void listView1_MouseClick(object sender, MouseEventArgs e) { ListView listView = (ListView)sender; ListViewItem item = listView.GetItemAt(e.X, e.Y); if (item != null && e.Button == MouseButtons.Right) { this.contextMenuStrip1.Show(listView, e.X, e.Y); } } /// /// 右键保存 /// /// /// private void toolStripMenuItem1_Click(object sender, EventArgs e) { if (AppWorkspace.ActiveDocumentWorkspace != null) { if (AppWorkspace.startScriptRecording) { AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List()); } AppWorkspace.ActiveDocumentWorkspace.GraphicsList.UnselectAll(); AppWorkspace.ActiveDocumentWorkspace.DoSaveNew(); } InitData(); } /// /// 右键另存 /// /// /// private void toolStripMenuItem2_Click(object sender, EventArgs e) { if (AppWorkspace.ActiveDocumentWorkspace != null) { if (AppWorkspace.startScriptRecording) { AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List()); } AppWorkspace.ActiveDocumentWorkspace.GraphicsList.UnselectAll(); AppWorkspace.ActiveDocumentWorkspace.DoSaveAsNew(); } InitData(); } /// /// 右键强制关闭 /// /// /// private void toolStripMenuItem3_Click(object sender, EventArgs e) { if (this.AppWorkspace.DocumentWorkspaces.Length > 0 && this.AppWorkspace.ActiveDocumentWorkspace != null) { if (AppWorkspace.startScriptRecording) { AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List()); } this.AppWorkspace.ActiveDocumentWorkspace.Document.Dirty = false; this.AppWorkspace.PerformAction(new CloseWorkspaceAction()); } InitData(); } private Bitmap copyedBitmap;//复制的图片 private int nameNum = 0;//命名使用 /// /// 右键复制图片 /// /// /// private void toolStripMenuItem4_Click(object sender, EventArgs e) { if (AppWorkspace.ActiveDocumentWorkspace != null && AppWorkspace.ActiveDocumentWorkspace.CompositionSurface != null) { if (AppWorkspace.startScriptRecording) { AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List()); } Bitmap temp = AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreateAliasedBitmap(); copyedBitmap = new Bitmap(temp.Width, temp.Height); Graphics graphics = Graphics.FromImage(copyedBitmap); graphics.DrawImage(temp, 0, 0, temp.Width, temp.Height); if (AppWorkspace.ActiveDocumentWorkspace.GraphicsList.IsExsitSpecificObject(DrawToolType.ImageCut)) { //获取裁剪的矩形区域 List objList = AppWorkspace.ActiveDocumentWorkspace.GraphicsList.GetDrawToolTypeList(DrawToolType.ImageCut); ImageCutDraw imageCutDraw = (ImageCutDraw)objList[0]; RectangleF cutRectangle = imageCutDraw.Rectangle; copyedBitmap = DrawRulerHelper.KiCut(copyedBitmap, (int)cutRectangle.X, (int)cutRectangle.Y, (int)cutRectangle.Width, (int)cutRectangle.Height); } } if (copyedBitmap != null) { if (AppWorkspace.startScriptRecording) { AppWorkspace.SetScriptStartRecording(((PdnMenuItem)sender).MenuId, ((PdnMenuItem)sender).Text, new List()); } DocumentWorkspace dw = AppWorkspace.AddNewDocumentWorkspace(); Document document = Document.FromImageMat(Camera.Tools.ToMat(copyedBitmap)); dw.Document = document; //图片命名 nameNum++; int numLength = nameNum.ToString().Length; string joinName = ""; switch (numLength) { case 1: joinName = "00" + nameNum; break; case 2: joinName = "0" + nameNum; break; default: joinName = nameNum.ToString(); break; } dw.xmlSaveModel = AppWorkspace.ActiveDocumentWorkspace.xmlSaveModel; dw.rules = AppWorkspace.ActiveDocumentWorkspace.rules; dw.fileText = PdnResources.GetString("Menu.Copythepicture.Text") + "-" + joinName; AppWorkspace.ActiveDocumentWorkspace = dw; } InitData(); } private void SplitContainerSize() { splitContainer1.Size = new Size(800, 450); } private void comboBox_T1_SelectedIndexChanged(object sender, EventArgs e) { TxtAssignment(); PreviewRefresh(config.CaptureSaveMode); } private void comboBox_T2_SelectedIndexChanged(object sender, EventArgs e) { TxtAssignment(); PreviewRefresh(config.CaptureSaveMode); } private void comboBox_T3_SelectedIndexChanged(object sender, EventArgs e) { TxtAssignment(); PreviewRefresh(config.CaptureSaveMode); } private void comboBox_Name_SelectedIndexChanged(object sender, EventArgs e) { if (comboBox_Name.Text.Trim() == "") { MessageBox.Show("参数不能为空!"); return; } config.CurrentName = comboBox_Name.Text.Trim(); comboBox_Name_SelectedIndex(); string configXml = XmlSerializeHelper.XmlSerialize(config); string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml"; if (!FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create)) MessageBox.Show(PdnResources.GetString("Menu.mingconventionsavefailed.text")); PreviewRefresh(config.CaptureSaveMode); } private void comboBox_Name_SelectedIndex() { string CurrentName = config.CurrentName; if (config.LstNaming.Count > 0) { foreach (NamingMethod item in config.LstNaming) { if (CurrentName.Equals(item.name)) { config.NamePrefix = item.NamePrefix; config.NameFormat = item.NameFormat; config.NumberNum = item.NumberNum; config.NameStatus = item.NameStatus; config.ContinueNum = item.ContinueNum; } } } } CreateNameDialog dialog; public string imgType = string.Empty; private void listView1_MouseDoubleClick(object sender, MouseEventArgs e) { string imgName = this.AppWorkspace.DocumentWorkspaces[AppWorkspace.DocumentWorkspaces.Length - 1 - this.listView1.FocusedItem.Index].GetFriendlyName(); int index = 0; if (imgName.Contains('.')) { index = imgName.LastIndexOf('.'); imgType = imgName.Substring(index); //从下一个索引开始截取 imgName = imgName.Substring(0, index); } else { imgType = ""; } dialog = new CreateNameDialog(this); dialog.Text = "重命名"; dialog.StartPosition = FormStartPosition.CenterParent; dialog.SetTextBoxValue(imgName); dialog.textBox1.MaxLength = 999; dialog.ShowDialog(); } /// /// 新建文件夹的结果函数 /// /// public override void GetCreateName(string name) { DocumentWorkspace iDocumentWorkspace = AppWorkspace.DocumentWorkspaces[AppWorkspace.DocumentWorkspaces.Length - 1 - this.listView1.FocusedItem.Index]; string imgName = iDocumentWorkspace.GetFriendlyName(); int index = 0; if (imgName.Contains('.')) { index = imgName.LastIndexOf('.'); imgName = imgName.Substring(0, index); } //获取图片路径 string fileName; //FileType fileType; //SaveConfigToken saveConfigToken; iDocumentWorkspace.GetDocumentSaveOptions(out fileName/*, out fileType, out saveConfigToken*/); string path = Path.GetDirectoryName(fileName); string filePath = path == null? "" : path + "\\" + name + imgType; string xmlName = path == null ? "" : path + "\\" + imgName + ".xml"; string xmlPath = path == null ? "" : path + "\\" + name + ".xml"; if (System.IO.File.Exists(fileName)) System.IO.File.Move(fileName, filePath);//更改图片名称 if (System.IO.File.Exists(xmlName)) System.IO.File.Move(xmlName, xmlPath);//更改xml文件名称 this.AppWorkspace.DocumentWorkspaces[AppWorkspace.DocumentWorkspaces.Length - 1 - this.listView1.FocusedItem.Index].fileText = name + imgType; this.AppWorkspace.DocumentWorkspaces[AppWorkspace.DocumentWorkspaces.Length - 1 - this.listView1.FocusedItem.Index].UpdateDw2buttonName(name + imgType); if (path != null) { this.AppWorkspace.DocumentWorkspaces[AppWorkspace.DocumentWorkspaces.Length - 1 - this.listView1.FocusedItem.Index].picName = name + imgType; this.AppWorkspace.DocumentWorkspaces[AppWorkspace.DocumentWorkspaces.Length - 1 - this.listView1.FocusedItem.Index].filePath = filePath; this.listView1.Items[this.listView1.FocusedItem.Index].Text = name + imgType; } this.AppWorkspace.DocumentWorkspaces[AppWorkspace.DocumentWorkspaces.Length - 1 - this.listView1.FocusedItem.Index].Refresh(); this.listView1.Items[this.listView1.FocusedItem.Index].Name = name + imgType; //InitData(); dialog.Close(); } private void ImageIndexDialog_FormClosing(object sender, FormClosingEventArgs e) { this.AppWorkspace.toolBar.RefreshBtnSelect(false, "ImageIndex"); this.AppWorkspace.toolsPanel.RefreshBtnSelect(false, "ImageIndex"); config.Txt1 = comboBox_T1.Text; config.Txt2 = comboBox_T2.Text; config.Txt3 = comboBox_T2.Text; } } }