123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338 |
- using System;
- using System.ComponentModel;
- using System.Drawing;
- using System.Windows.Forms;
- namespace PaintDotNet.Processing
- {
- /// <summary>
- /// 图库
- /// </summary>
- internal partial class InterImagePickerDialog : PdnBaseForm
- {
- /// <summary>
- /// 参数值改变
- /// </summary>
- public event EventHandler ValueChanged;
- private Button button1;
- private ListView listView1;
- private ImageList imageList1;
- /// <summary>
- /// 主控件
- /// </summary>
- private AppWorkspace appWorkspace;
- [Browsable(false)]
- public AppWorkspace AppWorkspace
- {
- get
- {
- return this.appWorkspace;
- }
- set
- {
- this.appWorkspace = value;
- }
- }
- public InterImagePickerDialog(AppWorkspace appWorkspace)
- {
- this.appWorkspace = appWorkspace;
- //this.collection = this.appWorkspace.ToolBar.MainMenu.Items;
- this.ShowInTaskbar = false;
- InitializeComponent();
- this.button1.Text = PdnResources.GetString("Menu.File.Close.Text");
- this.InitDataGridView1UI();
- this.InitListView1Data();
- this.listView1.SelectedIndexChanged += new EventHandler(dataGridView1_CellMouseClick);
- }
- /// <summary>
- /// 初始化脚本内容的DataGridView的表头
- /// </summary>
- private void InitDataGridView1UI()
- {
- /*DataGridViewTextBoxColumn h1 = new DataGridViewTextBoxColumn();
- h1.Width = 99;
- h1.HeaderText = "图像第1列";
- DataGridViewTextBoxColumn h2 = new DataGridViewTextBoxColumn();
- h2.Width = 99;
- h2.HeaderText = "图像第2列";
- DataGridViewTextBoxColumn*//*DataGridViewTextBoxColumn*//* h3 = new DataGridViewTextBoxColumn();
- h3.Width = 99;
- h3.HeaderText = "图像第3列";
- DataGridViewTextBoxColumn*//*DataGridViewComboBoxColumn*//* h4 = new DataGridViewTextBoxColumn();
- h4.Width = 99;
- h4.HeaderText = "图像第4列";
- this.dataGridView1.Columns.Add(h1);
- this.dataGridView1.Columns.Add(h2);
- this.dataGridView1.Columns.Add(h3);
- this.dataGridView1.Columns.Add(h4);
- ////this.dataGridView1.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
- ////this.dataGridView1.Columns[0].ReadOnly = true;
- //this.dataGridView1.UpdateRowHeightInfo();
- this.dataGridView1.AllowUserToResizeRows = false;
- this.dataGridView1.AllowUserToResizeColumns = false;*/
- }
- /// <summary>
- /// 初始化图片列表
- /// </summary>
- private void InitListView1Data()
- {
- this.imageList1.Images.Clear();
- this.listView1.Items.Clear();
- for (int i = 0; i < AppWorkspace.DocumentWorkspaces.Length; i++)
- {
- //原图
- Bitmap primaryBitmap = AppWorkspace.DocumentWorkspaces[i].CompositionSurface.CreateAliasedBitmap();
- //克隆原图
- Bitmap newBit = primaryBitmap.Clone(new Rectangle(0, 0, primaryBitmap.Width, primaryBitmap.Height), primaryBitmap.PixelFormat);
- this.imageList1.ImageSize = new System.Drawing.Size(64, 64);
- this.imageList1.Images.Add("img" + i, AppWorkspace.DocumentWorkspaces[i].NewPanelBitmap(newBit));
- //this.imageList1.Images[i] = AppWorkspace.DocumentWorkspaces[i].panelBitmap(true);
- this.listView1.Items.Add("", i);
- //this.listView1.Items[i].Tag = lists[i].id;
- this.listView1.Items[i].ImageIndex = i;
- this.listView1.Items[i].Text = AppWorkspace.DocumentWorkspaces[i].GetFriendlyName();
- }
- /*
- int columnCount = 0;
- int.TryParse(Math.Ceiling((double)AppWorkspace.DocumentWorkspaces.Length / (double)4.0).ToString(), out columnCount);
- //初始化图片列表
- for (int i = 0; i < columnCount; i++)
- {
- DataGridViewRow row = new DataGridViewRow();
- row.Height = 99;
- for (int j = 0; j < 4; j++)
- {
- if (j < Math.Min(4, AppWorkspace.DocumentWorkspaces.Length - 4 * i))
- {
- row.Cells.Add(CreateImageBoxCell(4 * i + j, 4 * i + j));
- }
- else
- {
- break;
- //DataGridViewTextBoxCell imageCell = new DataGridViewTextBoxCell();
- ////imageCell.Visible = false;
- //////imageCell.Description = "";// AppWorkspace.DocumentWorkspaces[index].GetFriendlyName();
- //imageCell.Value = "";// AppWorkspace.DocumentWorkspaces[index].SurfaceBox.Surface.CreateAliasedBitmap();
- //imageCell.Tag = 4 * i + j;
- //row.Cells.Add(imageCell);
- }
- }
- this.dataGridView1.Rows.Add(row);
- }*/
- }
- /// <summary>
- /// 创建一个InterImageDataGridViewCell
- /// </summary>
- /// <param name="text"></param>
- /// <param name="tag"></param>
- /// <returns></returns>
- private InterImageDataGridViewCell CreateImageBoxCell(int index, object tag)
- {
- InterImageDataGridViewCell imageCell = new InterImageDataGridViewCell();
- imageCell.Description = AppWorkspace.DocumentWorkspaces[index].GetFriendlyName();
- imageCell.Value = AppWorkspace.DocumentWorkspaces[index].CompositionSurface.Thumbnail; //CreateAliasedBitmap();
- imageCell.Tag = tag;
- return imageCell;
- }
- private void PickerDialog_MouseClick(object sender, MouseEventArgs e)
- {
- this.Close();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- private void dataGridView1_CellMouseClick(object sender, EventArgs e)
- {
- if (this.listView1.FocusedItem != null && this.listView1.FocusedItem.Selected)
- {
- DocumentWorkspace workspace = AppWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index];
- if (this.ValueChanged != null)
- {
- this.ValueChanged(workspace, e);
- }
- this.Close();
- }
- /*if (this.dataGridView1.CurrentCell.ColumnIndex + 4 * this.dataGridView1.CurrentRow.Index >= AppWorkspace.DocumentWorkspaces.Length)
- return;
- */
- }
- private void PickerDialog_Leave(object sender, EventArgs e)
- {
- this.Close();
- }
- ///// <summary>
- ///// 创建一个InterImageDataGridViewCell
- ///// </summary>
- ///// <param name="text"></param>
- ///// <param name="tag"></param>
- ///// <returns></returns>
- //private InterImageDataGridViewCell CreateTextBoxCell(string text, object tag)
- //{
- // //DataGridViewComboBoxCell
- // //DataGridViewCell
- // InterImageDataGridViewCell imageCell = new InterImageDataGridViewCell();
- // //imageCell.
- // imageCell.Description = AppWorkspace.DocumentWorkspaces[0/*i*/].GetFriendlyName();
- // imageCell.Value = AppWorkspace.DocumentWorkspaces[0/*i*/].SurfaceBox.Surface.CreateAliasedBitmap();
- // imageCell.Tag = tag;
- // //DataGridViewTextBoxCell textboxcell = new DataGridViewTextBoxCell();
- // //textboxcell.Value = text;
- // //textboxcell.Tag = tag;
- // return imageCell;
- //}
- private void InterImagePickerDialog_Load(object sender, EventArgs e)
- {
- /*for (int i = 0; i < dataGridView1.Rows.Count; i++)
- {
- for (int j = 0; j < dataGridView1.Columns.Count; j++)
- {
- if (4 * i + j >= AppWorkspace.DocumentWorkspaces.Length)
- break;
- //获取第一行第一列单元格位置
- Rectangle rectangle = dataGridView1.GetCellDisplayRectangle(j, i, true);
- //获取横坐标
- int x = rectangle.Location.X;
- //获取纵坐标
- int y = rectangle.Location.Y;
- Label label = new Label();
- label.Location = new Point(x, y + rectangle.Height - 18);
- label.Width = rectangle.Width;
- label.Height = 18;
- label.ForeColor = Color.Black;
- label.AutoEllipsis = true;
- label.TextAlign = ContentAlignment.MiddleCenter;
- label.Text = AppWorkspace.DocumentWorkspaces[4 * i + j].GetFriendlyName();
- this.dataGridView1.Controls.Add(label);
- }
- }*/
- }
- ///// <summary>
- ///// 创建一个DataGridViewComboBoxCell
- ///// </summary>
- ///// <param name="value"></param>
- ///// <returns></returns>
- //private DataGridViewComboBoxCell CreateComboBoxCell(int value)
- //{
- // DataGridViewComboBoxCell comboxcell = new DataGridViewComboBoxCell();
- // comboxcell.DataSource = new BindingSource(InvariantData.scriptDictionary, null);
- // comboxcell.DisplayMember = "Value";
- // comboxcell.ValueMember = "Key";
- // comboxcell.Value = value;
- // return comboxcell;
- //}
- /// <summary>
- /// Required designer variable.
- /// </summary>
- private System.ComponentModel.IContainer components = null;
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
- protected override void Dispose(bool disposing)
- {
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
- #region Windows Form Designer generated code
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- this.components = new System.ComponentModel.Container();
- this.button1 = new System.Windows.Forms.Button();
- this.listView1 = new System.Windows.Forms.ListView();
- this.imageList1 = new System.Windows.Forms.ImageList(this.components);
- this.SuspendLayout();
- //
- // button1
- //
- this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.button1.Location = new System.Drawing.Point(395, 371);
- this.button1.Name = "button1";
- this.button1.Size = new System.Drawing.Size(75, 23);
- this.button1.TabIndex = 0;
- this.button1.Text = "关闭";
- this.button1.UseVisualStyleBackColor = true;
- this.button1.Click += new System.EventHandler(this.button1_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(3, 3);
- this.listView1.Name = "listView1";
- this.listView1.Size = new System.Drawing.Size(467, 360);
- this.listView1.TabIndex = 1;
- this.listView1.UseCompatibleStateImageBehavior = false;
- //
- // imageList1
- //
- this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
- this.imageList1.ImageSize = new System.Drawing.Size(64, 64);
- this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
- //
- // InterImagePickerDialog
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(473, 404);
- this.Controls.Add(this.listView1);
- this.Controls.Add(this.button1);
- this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
- this.Name = "InterImagePickerDialog";
- this.Text = "InterImagePickerDialog";
- this.TopMost = true;
- this.Load += new System.EventHandler(this.InterImagePickerDialog_Load);
- this.Leave += new System.EventHandler(this.PickerDialog_Leave);
- this.MouseClick += new System.Windows.Forms.MouseEventHandler(this.PickerDialog_MouseClick);
- this.Controls.SetChildIndex(this.button1, 0);
- this.Controls.SetChildIndex(this.listView1, 0);
- this.ResumeLayout(false);
- }
- #endregion
-
- }
- }
|