using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace PaintDotNet.Processing
{
///
/// 图库
///
internal partial class InterImagePickerDialog : PdnBaseForm
{
///
/// 参数值改变
///
public event EventHandler ValueChanged;
private Button button1;
private ListView listView1;
private ImageList imageList1;
///
/// 主控件
///
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);
}
///
/// 初始化脚本内容的DataGridView的表头
///
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;*/
}
///
/// 初始化图片列表
///
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);
}*/
}
///
/// 创建一个InterImageDataGridViewCell
///
///
///
///
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();
}
/////
///// 创建一个InterImageDataGridViewCell
/////
/////
/////
/////
//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);
}
}*/
}
/////
///// 创建一个DataGridViewComboBoxCell
/////
/////
/////
//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;
//}
///
/// 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.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
}
}