InterImagePickerDialog.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. using System;
  2. using System.ComponentModel;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. namespace PaintDotNet.Processing
  6. {
  7. /// <summary>
  8. /// 图库
  9. /// </summary>
  10. internal partial class InterImagePickerDialog : PdnBaseForm
  11. {
  12. /// <summary>
  13. /// 参数值改变
  14. /// </summary>
  15. public event EventHandler ValueChanged;
  16. private Button button1;
  17. private ListView listView1;
  18. private ImageList imageList1;
  19. /// <summary>
  20. /// 主控件
  21. /// </summary>
  22. private AppWorkspace appWorkspace;
  23. [Browsable(false)]
  24. public AppWorkspace AppWorkspace
  25. {
  26. get
  27. {
  28. return this.appWorkspace;
  29. }
  30. set
  31. {
  32. this.appWorkspace = value;
  33. }
  34. }
  35. public InterImagePickerDialog(AppWorkspace appWorkspace)
  36. {
  37. this.appWorkspace = appWorkspace;
  38. //this.collection = this.appWorkspace.ToolBar.MainMenu.Items;
  39. this.ShowInTaskbar = false;
  40. InitializeComponent();
  41. this.button1.Text = PdnResources.GetString("Menu.File.Close.Text");
  42. this.InitDataGridView1UI();
  43. this.InitListView1Data();
  44. this.listView1.SelectedIndexChanged += new EventHandler(dataGridView1_CellMouseClick);
  45. }
  46. /// <summary>
  47. /// 初始化脚本内容的DataGridView的表头
  48. /// </summary>
  49. private void InitDataGridView1UI()
  50. {
  51. /*DataGridViewTextBoxColumn h1 = new DataGridViewTextBoxColumn();
  52. h1.Width = 99;
  53. h1.HeaderText = "图像第1列";
  54. DataGridViewTextBoxColumn h2 = new DataGridViewTextBoxColumn();
  55. h2.Width = 99;
  56. h2.HeaderText = "图像第2列";
  57. DataGridViewTextBoxColumn*//*DataGridViewTextBoxColumn*//* h3 = new DataGridViewTextBoxColumn();
  58. h3.Width = 99;
  59. h3.HeaderText = "图像第3列";
  60. DataGridViewTextBoxColumn*//*DataGridViewComboBoxColumn*//* h4 = new DataGridViewTextBoxColumn();
  61. h4.Width = 99;
  62. h4.HeaderText = "图像第4列";
  63. this.dataGridView1.Columns.Add(h1);
  64. this.dataGridView1.Columns.Add(h2);
  65. this.dataGridView1.Columns.Add(h3);
  66. this.dataGridView1.Columns.Add(h4);
  67. ////this.dataGridView1.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
  68. ////this.dataGridView1.Columns[0].ReadOnly = true;
  69. //this.dataGridView1.UpdateRowHeightInfo();
  70. this.dataGridView1.AllowUserToResizeRows = false;
  71. this.dataGridView1.AllowUserToResizeColumns = false;*/
  72. }
  73. /// <summary>
  74. /// 初始化图片列表
  75. /// </summary>
  76. private void InitListView1Data()
  77. {
  78. this.imageList1.Images.Clear();
  79. this.listView1.Items.Clear();
  80. for (int i = 0; i < AppWorkspace.DocumentWorkspaces.Length; i++)
  81. {
  82. //原图
  83. Bitmap primaryBitmap = AppWorkspace.DocumentWorkspaces[i].CompositionSurface.CreateAliasedBitmap();
  84. //克隆原图
  85. Bitmap newBit = primaryBitmap.Clone(new Rectangle(0, 0, primaryBitmap.Width, primaryBitmap.Height), primaryBitmap.PixelFormat);
  86. this.imageList1.ImageSize = new System.Drawing.Size(64, 64);
  87. this.imageList1.Images.Add("img" + i, AppWorkspace.DocumentWorkspaces[i].NewPanelBitmap(newBit));
  88. //this.imageList1.Images[i] = AppWorkspace.DocumentWorkspaces[i].panelBitmap(true);
  89. this.listView1.Items.Add("", i);
  90. //this.listView1.Items[i].Tag = lists[i].id;
  91. this.listView1.Items[i].ImageIndex = i;
  92. this.listView1.Items[i].Text = AppWorkspace.DocumentWorkspaces[i].GetFriendlyName();
  93. }
  94. /*
  95. int columnCount = 0;
  96. int.TryParse(Math.Ceiling((double)AppWorkspace.DocumentWorkspaces.Length / (double)4.0).ToString(), out columnCount);
  97. //初始化图片列表
  98. for (int i = 0; i < columnCount; i++)
  99. {
  100. DataGridViewRow row = new DataGridViewRow();
  101. row.Height = 99;
  102. for (int j = 0; j < 4; j++)
  103. {
  104. if (j < Math.Min(4, AppWorkspace.DocumentWorkspaces.Length - 4 * i))
  105. {
  106. row.Cells.Add(CreateImageBoxCell(4 * i + j, 4 * i + j));
  107. }
  108. else
  109. {
  110. break;
  111. //DataGridViewTextBoxCell imageCell = new DataGridViewTextBoxCell();
  112. ////imageCell.Visible = false;
  113. //////imageCell.Description = "";// AppWorkspace.DocumentWorkspaces[index].GetFriendlyName();
  114. //imageCell.Value = "";// AppWorkspace.DocumentWorkspaces[index].SurfaceBox.Surface.CreateAliasedBitmap();
  115. //imageCell.Tag = 4 * i + j;
  116. //row.Cells.Add(imageCell);
  117. }
  118. }
  119. this.dataGridView1.Rows.Add(row);
  120. }*/
  121. }
  122. /// <summary>
  123. /// 创建一个InterImageDataGridViewCell
  124. /// </summary>
  125. /// <param name="text"></param>
  126. /// <param name="tag"></param>
  127. /// <returns></returns>
  128. private InterImageDataGridViewCell CreateImageBoxCell(int index, object tag)
  129. {
  130. InterImageDataGridViewCell imageCell = new InterImageDataGridViewCell();
  131. imageCell.Description = AppWorkspace.DocumentWorkspaces[index].GetFriendlyName();
  132. imageCell.Value = AppWorkspace.DocumentWorkspaces[index].CompositionSurface.Thumbnail; //CreateAliasedBitmap();
  133. imageCell.Tag = tag;
  134. return imageCell;
  135. }
  136. private void PickerDialog_MouseClick(object sender, MouseEventArgs e)
  137. {
  138. this.Close();
  139. }
  140. private void button1_Click(object sender, EventArgs e)
  141. {
  142. this.Close();
  143. }
  144. private void dataGridView1_CellMouseClick(object sender, EventArgs e)
  145. {
  146. if (this.listView1.FocusedItem != null && this.listView1.FocusedItem.Selected)
  147. {
  148. DocumentWorkspace workspace = AppWorkspace.DocumentWorkspaces[this.listView1.FocusedItem.Index];
  149. if (this.ValueChanged != null)
  150. {
  151. this.ValueChanged(workspace, e);
  152. }
  153. this.Close();
  154. }
  155. /*if (this.dataGridView1.CurrentCell.ColumnIndex + 4 * this.dataGridView1.CurrentRow.Index >= AppWorkspace.DocumentWorkspaces.Length)
  156. return;
  157. */
  158. }
  159. private void PickerDialog_Leave(object sender, EventArgs e)
  160. {
  161. this.Close();
  162. }
  163. ///// <summary>
  164. ///// 创建一个InterImageDataGridViewCell
  165. ///// </summary>
  166. ///// <param name="text"></param>
  167. ///// <param name="tag"></param>
  168. ///// <returns></returns>
  169. //private InterImageDataGridViewCell CreateTextBoxCell(string text, object tag)
  170. //{
  171. // //DataGridViewComboBoxCell
  172. // //DataGridViewCell
  173. // InterImageDataGridViewCell imageCell = new InterImageDataGridViewCell();
  174. // //imageCell.
  175. // imageCell.Description = AppWorkspace.DocumentWorkspaces[0/*i*/].GetFriendlyName();
  176. // imageCell.Value = AppWorkspace.DocumentWorkspaces[0/*i*/].SurfaceBox.Surface.CreateAliasedBitmap();
  177. // imageCell.Tag = tag;
  178. // //DataGridViewTextBoxCell textboxcell = new DataGridViewTextBoxCell();
  179. // //textboxcell.Value = text;
  180. // //textboxcell.Tag = tag;
  181. // return imageCell;
  182. //}
  183. private void InterImagePickerDialog_Load(object sender, EventArgs e)
  184. {
  185. /*for (int i = 0; i < dataGridView1.Rows.Count; i++)
  186. {
  187. for (int j = 0; j < dataGridView1.Columns.Count; j++)
  188. {
  189. if (4 * i + j >= AppWorkspace.DocumentWorkspaces.Length)
  190. break;
  191. //获取第一行第一列单元格位置
  192. Rectangle rectangle = dataGridView1.GetCellDisplayRectangle(j, i, true);
  193. //获取横坐标
  194. int x = rectangle.Location.X;
  195. //获取纵坐标
  196. int y = rectangle.Location.Y;
  197. Label label = new Label();
  198. label.Location = new Point(x, y + rectangle.Height - 18);
  199. label.Width = rectangle.Width;
  200. label.Height = 18;
  201. label.ForeColor = Color.Black;
  202. label.AutoEllipsis = true;
  203. label.TextAlign = ContentAlignment.MiddleCenter;
  204. label.Text = AppWorkspace.DocumentWorkspaces[4 * i + j].GetFriendlyName();
  205. this.dataGridView1.Controls.Add(label);
  206. }
  207. }*/
  208. }
  209. ///// <summary>
  210. ///// 创建一个DataGridViewComboBoxCell
  211. ///// </summary>
  212. ///// <param name="value"></param>
  213. ///// <returns></returns>
  214. //private DataGridViewComboBoxCell CreateComboBoxCell(int value)
  215. //{
  216. // DataGridViewComboBoxCell comboxcell = new DataGridViewComboBoxCell();
  217. // comboxcell.DataSource = new BindingSource(InvariantData.scriptDictionary, null);
  218. // comboxcell.DisplayMember = "Value";
  219. // comboxcell.ValueMember = "Key";
  220. // comboxcell.Value = value;
  221. // return comboxcell;
  222. //}
  223. /// <summary>
  224. /// Required designer variable.
  225. /// </summary>
  226. private System.ComponentModel.IContainer components = null;
  227. /// <summary>
  228. /// Clean up any resources being used.
  229. /// </summary>
  230. /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
  231. protected override void Dispose(bool disposing)
  232. {
  233. if (disposing && (components != null))
  234. {
  235. components.Dispose();
  236. }
  237. base.Dispose(disposing);
  238. }
  239. #region Windows Form Designer generated code
  240. /// <summary>
  241. /// Required method for Designer support - do not modify
  242. /// the contents of this method with the code editor.
  243. /// </summary>
  244. private void InitializeComponent()
  245. {
  246. this.components = new System.ComponentModel.Container();
  247. this.button1 = new System.Windows.Forms.Button();
  248. this.listView1 = new System.Windows.Forms.ListView();
  249. this.imageList1 = new System.Windows.Forms.ImageList(this.components);
  250. this.SuspendLayout();
  251. //
  252. // button1
  253. //
  254. this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
  255. this.button1.Location = new System.Drawing.Point(395, 371);
  256. this.button1.Name = "button1";
  257. this.button1.Size = new System.Drawing.Size(75, 23);
  258. this.button1.TabIndex = 0;
  259. this.button1.Text = "关闭";
  260. this.button1.UseVisualStyleBackColor = true;
  261. this.button1.Click += new System.EventHandler(this.button1_Click);
  262. //
  263. // listView1
  264. //
  265. this.listView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  266. | System.Windows.Forms.AnchorStyles.Left)
  267. | System.Windows.Forms.AnchorStyles.Right)));
  268. this.listView1.HideSelection = false;
  269. this.listView1.LargeImageList = this.imageList1;
  270. this.listView1.Location = new System.Drawing.Point(3, 3);
  271. this.listView1.Name = "listView1";
  272. this.listView1.Size = new System.Drawing.Size(467, 360);
  273. this.listView1.TabIndex = 1;
  274. this.listView1.UseCompatibleStateImageBehavior = false;
  275. //
  276. // imageList1
  277. //
  278. this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
  279. this.imageList1.ImageSize = new System.Drawing.Size(64, 64);
  280. this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
  281. //
  282. // InterImagePickerDialog
  283. //
  284. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
  285. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  286. this.ClientSize = new System.Drawing.Size(473, 404);
  287. this.Controls.Add(this.listView1);
  288. this.Controls.Add(this.button1);
  289. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
  290. this.Name = "InterImagePickerDialog";
  291. this.Text = "InterImagePickerDialog";
  292. this.TopMost = true;
  293. this.Load += new System.EventHandler(this.InterImagePickerDialog_Load);
  294. this.Leave += new System.EventHandler(this.PickerDialog_Leave);
  295. this.MouseClick += new System.Windows.Forms.MouseEventHandler(this.PickerDialog_MouseClick);
  296. this.Controls.SetChildIndex(this.button1, 0);
  297. this.Controls.SetChildIndex(this.listView1, 0);
  298. this.ResumeLayout(false);
  299. }
  300. #endregion
  301. }
  302. }