using System; using System.Collections.Generic; using System.Drawing; using System.IO; using System.Windows.Forms; using PaintDotNet.Base.CommTool; using PaintDotNet.Base.SettingModel; namespace PaintDotNet.GeneralAnalysis { internal partial class ArtworkSettingDialog : PdnBaseForm { private string m_filePath = Application.StartupPath + "\\Artwork\\"; private AppWorkspace m_appWorkspace; private ArtworkModel m_artworkModel; private List m_artworkLists = new List(); private int m_selectIndex = -1; public ArtworkSettingDialog(AppWorkspace workspace) { m_appWorkspace = workspace; InitializeComponent(); InitializeLanguageText(); InitializeData(); } private void InitializeData() { this.ArtworkListLoad(); } private void btnDelete_Click(object sender, EventArgs e) { if (lvwArtworkList.SelectedItems.Count <= 0) { MessageBox.Show(PdnResources.GetString("Menu.Pleaseseledeleted.text")); return; } DialogResult result = MessageBox.Show(PdnResources.GetString("Menu.Areyousuretmation.text")+"?", PdnResources.GetString("Menu.Tips.text"), MessageBoxButtons.OKCancel); if (result == DialogResult.OK) { for(int i= lvwArtworkList.SelectedItems.Count -1; i>=0;i--) { int index = lvwArtworkList.Items[lvwArtworkList.SelectedIndices[i]].Index; m_artworkLists.Remove(m_artworkLists[index]); } string stageModelXml = XmlSerializeHelper.XmlSerialize(m_artworkModel); string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\ArtworkModel.xml"; FileOperationHelper.WriteStringToFile(stageModelXml, filePath, FileMode.Create); Startup.instance.artworkModel = m_artworkModel; if (lvwArtworkList.SelectedItems.Count > 1) { m_selectIndex = -1; } else { m_selectIndex -= 1; } ArtworkListLoad(); } } private void btnAdd_Click(object sender, EventArgs e) { ArtworkSettingEditDialog dg = new ArtworkSettingEditDialog(this, m_appWorkspace, -1); dg.ShowDialog(); } private void btnEdit_Click(object sender, EventArgs e) { if (lvwArtworkList.SelectedItems.Count != 1) { MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectteatatime.text")); return; } Console.WriteLine("==" + m_selectIndex); ArtworkSettingEditDialog dg = new ArtworkSettingEditDialog(this, m_appWorkspace, m_selectIndex); dg.ShowDialog(); } public void ArtworkListLoad() { m_artworkModel = Startup.instance.artworkModel; m_artworkLists = m_artworkModel.items; this.imageList1.Images.Clear(); this.lvwArtworkList.Items.Clear(); for (int i = 0; i < m_artworkLists.Count; i++) { if (!System.IO.File.Exists(m_filePath + m_artworkLists[i].thumbnail)) { this.imageList1.Images.Add("img" + i, new Bitmap(90,90)); } else { Bitmap bit = (Bitmap)Image.FromFile(m_filePath + m_artworkLists[i].thumbnail); this.imageList1.Images.Add("img" + i, new Bitmap(bit)); bit.Dispose(); } this.lvwArtworkList.Items.Add("", i); this.lvwArtworkList.Items[i].ImageIndex = i; this.lvwArtworkList.Items[i].Text = m_artworkLists[i].artworkName; this.lvwArtworkList.Items[i].Name = m_artworkLists[i].artworkName; } if (m_artworkLists.Count > 0) { if (m_selectIndex != -1) { lvwArtworkList.Items[m_selectIndex].Selected = true; } else { lvwArtworkList.Items[0].Selected = true; m_selectIndex = 0; } } } private void lvwArtworkList_SelectedIndexChanged(object sender, EventArgs e) { if (lvwArtworkList.FocusedItem != null) { m_selectIndex = lvwArtworkList.Items.IndexOf(lvwArtworkList.FocusedItem); } } #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 private void InitializeLanguageText() { this.groupBox1.Text = PdnResources.GetString("Menu.operation.text"); this.btnDelete.Text = PdnResources.GetString("Menu.Edit.Delete.Text"); this.btnEdit.Text = PdnResources.GetString("Menu.Edit.Text"); this.btnAdd.Text = PdnResources.GetString("Menu.Addto.text"); this.groupBox2.Text = PdnResources.GetString("Menu.Generalanalysis.Processmparison.Processdrawinglist.text"); this.Text = PdnResources.GetString("Menu.Generalanalysis.Processmparison.Processdrawingsetting.text"); } /// /// 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.btnDelete = new System.Windows.Forms.Button(); this.btnEdit = new System.Windows.Forms.Button(); this.btnAdd = new System.Windows.Forms.Button(); this.groupBox2 = new System.Windows.Forms.GroupBox(); this.lvwArtworkList = new System.Windows.Forms.ListView(); this.imageList1 = new System.Windows.Forms.ImageList(this.components); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); this.SuspendLayout(); // // groupBox1 // this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.groupBox1.Controls.Add(this.btnDelete); this.groupBox1.Controls.Add(this.btnEdit); this.groupBox1.Controls.Add(this.btnAdd); this.groupBox1.Location = new System.Drawing.Point(12, 12); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(430, 73); this.groupBox1.TabIndex = 0; this.groupBox1.TabStop = false; this.groupBox1.Text = "操作"; // // btnDelete // this.btnDelete.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.btnDelete.Location = new System.Drawing.Point(333, 24); this.btnDelete.Name = "btnDelete"; this.btnDelete.Size = new System.Drawing.Size(75, 34); this.btnDelete.TabIndex = 2; this.btnDelete.Text = "删除"; this.btnDelete.UseVisualStyleBackColor = true; this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click); // // btnEdit // this.btnEdit.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.btnEdit.Location = new System.Drawing.Point(242, 24); this.btnEdit.Name = "btnEdit"; this.btnEdit.Size = new System.Drawing.Size(75, 34); this.btnEdit.TabIndex = 1; this.btnEdit.Text = "编辑"; this.btnEdit.UseVisualStyleBackColor = true; this.btnEdit.Click += new System.EventHandler(this.btnEdit_Click); // // btnAdd // this.btnAdd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.btnAdd.Location = new System.Drawing.Point(151, 24); this.btnAdd.Name = "btnAdd"; this.btnAdd.Size = new System.Drawing.Size(75, 34); this.btnAdd.TabIndex = 0; this.btnAdd.Text = "添加"; this.btnAdd.UseVisualStyleBackColor = true; this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click); // // groupBox2 // this.groupBox2.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.groupBox2.Controls.Add(this.lvwArtworkList); this.groupBox2.Location = new System.Drawing.Point(12, 91); this.groupBox2.Name = "groupBox2"; this.groupBox2.Size = new System.Drawing.Size(430, 523); this.groupBox2.TabIndex = 1; this.groupBox2.TabStop = false; this.groupBox2.Text = "工艺图列表"; // // lvwArtworkList // this.lvwArtworkList.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.lvwArtworkList.HideSelection = false; this.lvwArtworkList.LargeImageList = this.imageList1; this.lvwArtworkList.Location = new System.Drawing.Point(20, 34); this.lvwArtworkList.Name = "lvwArtworkList"; this.lvwArtworkList.Size = new System.Drawing.Size(389, 471); this.lvwArtworkList.TabIndex = 4; this.lvwArtworkList.TileSize = new System.Drawing.Size(358, 90); this.lvwArtworkList.UseCompatibleStateImageBehavior = false; this.lvwArtworkList.View = System.Windows.Forms.View.Tile; this.lvwArtworkList.SelectedIndexChanged += new System.EventHandler(this.lvwArtworkList_SelectedIndexChanged); this.lvwArtworkList.Resize += new System.EventHandler(this.lvwArtworkList_Resize); // // imageList1 // this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit; this.imageList1.ImageSize = new System.Drawing.Size(90, 90); this.imageList1.TransparentColor = System.Drawing.Color.Transparent; // // ArtworkSettingDialog // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(454, 626); this.Controls.Add(this.groupBox2); this.Controls.Add(this.groupBox1); this.Name = "ArtworkSettingDialog"; this.Text = "工艺图设定"; this.Controls.SetChildIndex(this.groupBox1, 0); this.Controls.SetChildIndex(this.groupBox2, 0); this.groupBox1.ResumeLayout(false); this.groupBox2.ResumeLayout(false); this.ResumeLayout(false); } #endregion private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.Button btnDelete; private System.Windows.Forms.Button btnEdit; private System.Windows.Forms.Button btnAdd; private System.Windows.Forms.GroupBox groupBox2; private System.Windows.Forms.ImageList imageList1; private System.Windows.Forms.ListView lvwArtworkList; #endregion private void lvwArtworkList_Resize(object sender, EventArgs e) { this.lvwArtworkList.TileSize = new Size(lvwArtworkList.Width - 30, 90); } } }