LabelTextControl.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. using System.Collections;
  5. using PaintDotNet.Base.SettingModel;
  6. namespace PaintDotNet.Setting.LabelComponent
  7. {
  8. /// <summary>
  9. /// 标注设置-文本设置组件
  10. /// </summary>
  11. public class LabelTextControl : UserControl
  12. {
  13. #region 控件
  14. private Label label1;
  15. private Label label2;
  16. private Label label3;
  17. private Label label4;
  18. private Label label5;
  19. private Panel panel1;
  20. private Panel panel2;
  21. private Panel panel3;
  22. private ComboBox comboBox1;
  23. private NumericUpDown numericUpDown1;
  24. private NumericUpDown numericUpDown2;
  25. private System.Windows.Forms.Label label6;
  26. #endregion
  27. /// <summary>
  28. /// 文本样式
  29. /// </summary>
  30. private LabelStyleModel.Text model;
  31. PaintDotNet.ColorsForm colorsForm1;
  32. PaintDotNet.ColorsForm colorsForm2;
  33. PaintDotNet.ColorsForm colorsForm3;
  34. /// <summary>
  35. /// 字体列表
  36. /// </summary>
  37. ArrayList fontsItems = new ArrayList();
  38. public LabelTextControl(LabelStyleModel.Text model)
  39. {
  40. this.model = model;
  41. InitializeComponent();
  42. InitializeLanguageText();
  43. InitializeControlData();
  44. InitializeData();
  45. }
  46. /// <summary>
  47. /// 获取当前页面model值
  48. /// </summary>
  49. /// <returns></returns>
  50. public LabelStyleModel.Text getNowModel(LabelStyleModel.Text model)
  51. {
  52. model.font = this.comboBox1.Text;
  53. model.textColor = Convert.ToInt32(this.panel1.BackColor.ToArgb());
  54. model.backgroundColor = Convert.ToInt32(this.panel2.BackColor.ToArgb());
  55. model.backgroundBoxColor = Convert.ToInt32(this.panel3.BackColor.ToArgb());
  56. model.lineWidth = Convert.ToInt32(this.numericUpDown1.Value);
  57. model.fontSize = Convert.ToInt32(this.numericUpDown2.Value);
  58. return model;
  59. }
  60. /// <summary>
  61. /// 设置下拉等数据源
  62. /// </summary>
  63. private void InitializeControlData()
  64. {
  65. System.Drawing.Text.InstalledFontCollection fonts = new System.Drawing.Text.InstalledFontCollection();
  66. foreach (FontFamily fontFamily in fonts.Families)
  67. {
  68. fontsItems.Add(fontFamily.Name);
  69. }
  70. this.comboBox1.DataSource = fontsItems;
  71. }
  72. /// <summary>
  73. /// 绑定样式数据
  74. /// </summary>
  75. private void InitializeData()
  76. {
  77. this.comboBox1.Text = this.model.font;
  78. this.numericUpDown2.Value = this.model.fontSize;
  79. this.panel1.BackColor = Color.FromArgb(this.model.textColor);
  80. this.panel2.BackColor = Color.FromArgb(this.model.backgroundColor);
  81. this.panel3.BackColor = Color.FromArgb(this.model.backgroundBoxColor);
  82. this.numericUpDown1.Value = this.model.lineWidth;
  83. }
  84. private void InitializeLanguageText()
  85. {
  86. this.label1.Text = PdnResources.GetString("Menu.Textfont.text") + ":";
  87. this.label2.Text = PdnResources.GetString("Menu.Set.Rulersettings.Fontsize.text") + ":";
  88. this.label3.Text = PdnResources.GetString("Menu.Textcolor.text") + ":";
  89. this.label4.Text = PdnResources.GetString("Menu.backgroundcolor.text") + ":";
  90. this.label5.Text = PdnResources.GetString("Menu.Set.Labelsettings.Backgroundframecolor.text") + ":";
  91. this.label6.Text = PdnResources.GetString("Menu.Set.Labelsettings.Backgroundframewidth.text") + ":";
  92. }
  93. private void InitializeComponent()
  94. {
  95. this.label1 = new System.Windows.Forms.Label();
  96. this.comboBox1 = new System.Windows.Forms.ComboBox();
  97. this.label2 = new System.Windows.Forms.Label();
  98. this.label3 = new System.Windows.Forms.Label();
  99. this.panel1 = new System.Windows.Forms.Panel();
  100. this.panel2 = new System.Windows.Forms.Panel();
  101. this.label4 = new System.Windows.Forms.Label();
  102. this.label5 = new System.Windows.Forms.Label();
  103. this.label6 = new System.Windows.Forms.Label();
  104. this.panel3 = new System.Windows.Forms.Panel();
  105. this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
  106. this.numericUpDown2 = new System.Windows.Forms.NumericUpDown();
  107. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
  108. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit();
  109. this.SuspendLayout();
  110. //
  111. // label1
  112. //
  113. this.label1.AutoSize = true;
  114. this.label1.Location = new System.Drawing.Point(0, 8);
  115. this.label1.Name = "label1";
  116. this.label1.Size = new System.Drawing.Size(65, 12);
  117. this.label1.TabIndex = 0;
  118. //
  119. // comboBox1
  120. //
  121. this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  122. this.comboBox1.FormattingEnabled = true;
  123. this.comboBox1.Location = new System.Drawing.Point(95, 4);
  124. this.comboBox1.Name = "comboBox1";
  125. this.comboBox1.Size = new System.Drawing.Size(140, 20);
  126. this.comboBox1.TabIndex = 1;
  127. this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
  128. //
  129. // label2
  130. //
  131. this.label2.AutoSize = true;
  132. this.label2.Location = new System.Drawing.Point(0, 34);
  133. this.label2.Name = "label2";
  134. this.label2.Size = new System.Drawing.Size(65, 12);
  135. this.label2.TabIndex = 2;
  136. //
  137. // label3
  138. //
  139. this.label3.AutoSize = true;
  140. this.label3.Location = new System.Drawing.Point(0, 60);
  141. this.label3.Name = "label3";
  142. this.label3.Size = new System.Drawing.Size(65, 12);
  143. this.label3.TabIndex = 4;
  144. //
  145. // panel1
  146. //
  147. this.panel1.Location = new System.Drawing.Point(95, 57);
  148. this.panel1.Name = "panel1";
  149. this.panel1.Size = new System.Drawing.Size(140, 20);
  150. this.panel1.TabIndex = 5;
  151. this.panel1.Click += new System.EventHandler(this.panel1_Click);
  152. //
  153. // panel2
  154. //
  155. this.panel2.Location = new System.Drawing.Point(95, 83);
  156. this.panel2.Name = "panel2";
  157. this.panel2.Size = new System.Drawing.Size(140, 20);
  158. this.panel2.TabIndex = 7;
  159. this.panel2.Click += new System.EventHandler(this.panel2_Click);
  160. //
  161. // label4
  162. //
  163. this.label4.AutoSize = true;
  164. this.label4.Location = new System.Drawing.Point(0, 86);
  165. this.label4.Name = "label4";
  166. this.label4.Size = new System.Drawing.Size(65, 12);
  167. this.label4.TabIndex = 6;
  168. //
  169. // label5
  170. //
  171. this.label5.AutoSize = true;
  172. this.label5.Location = new System.Drawing.Point(0, 112);
  173. this.label5.Name = "label5";
  174. this.label5.Size = new System.Drawing.Size(77, 12);
  175. this.label5.TabIndex = 8;
  176. //
  177. // label6
  178. //
  179. this.label6.AutoSize = true;
  180. this.label6.Location = new System.Drawing.Point(0, 139);
  181. this.label6.Name = "label6";
  182. this.label6.Size = new System.Drawing.Size(77, 12);
  183. this.label6.TabIndex = 9;
  184. //
  185. // panel3
  186. //
  187. this.panel3.Location = new System.Drawing.Point(95, 109);
  188. this.panel3.Name = "panel3";
  189. this.panel3.Size = new System.Drawing.Size(140, 20);
  190. this.panel3.TabIndex = 10;
  191. this.panel3.Click += new System.EventHandler(this.panel3_Click);
  192. //
  193. // numericUpDown1
  194. //
  195. this.numericUpDown1.Location = new System.Drawing.Point(95, 135);
  196. this.numericUpDown1.Name = "numericUpDown1";
  197. this.numericUpDown1.Size = new System.Drawing.Size(140, 21);
  198. this.numericUpDown1.TabIndex = 11;
  199. this.numericUpDown1.ValueChanged += new System.EventHandler(this.numericUpDown1_ValueChanged);
  200. //
  201. // numericUpDown2
  202. //
  203. this.numericUpDown2.Location = new System.Drawing.Point(95, 30);
  204. this.numericUpDown2.Name = "numericUpDown2";
  205. this.numericUpDown2.Size = new System.Drawing.Size(140, 21);
  206. this.numericUpDown2.TabIndex = 12;
  207. this.numericUpDown2.ValueChanged += new System.EventHandler(this.numericUpDown2_ValueChanged);
  208. //
  209. // LabelTextControl
  210. //
  211. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
  212. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  213. this.Controls.Add(this.numericUpDown2);
  214. this.Controls.Add(this.numericUpDown1);
  215. this.Controls.Add(this.panel3);
  216. this.Controls.Add(this.label6);
  217. this.Controls.Add(this.label5);
  218. this.Controls.Add(this.panel2);
  219. this.Controls.Add(this.label4);
  220. this.Controls.Add(this.panel1);
  221. this.Controls.Add(this.label3);
  222. this.Controls.Add(this.label2);
  223. this.Controls.Add(this.comboBox1);
  224. this.Controls.Add(this.label1);
  225. this.Name = "LabelTextControl";
  226. this.Size = new System.Drawing.Size(239, 205);
  227. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
  228. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit();
  229. this.ResumeLayout(false);
  230. this.PerformLayout();
  231. this.colorsForm1 = new ColorsForm();
  232. this.colorsForm1.StartPosition = FormStartPosition.CenterScreen;
  233. this.colorsForm1.UserPrimaryColorChanged += new ColorEventHandler(this.colorsFormUserPrimaryColorChanged);
  234. this.colorsForm2 = new ColorsForm();
  235. this.colorsForm2.StartPosition = FormStartPosition.CenterScreen;
  236. this.colorsForm2.UserPrimaryColorChanged += new ColorEventHandler(this.colorsFormUserPrimaryColorChanged);
  237. this.colorsForm3 = new ColorsForm();
  238. this.colorsForm3.StartPosition = FormStartPosition.CenterScreen;
  239. this.colorsForm3.UserPrimaryColorChanged += new ColorEventHandler(this.colorsFormUserPrimaryColorChanged);
  240. }
  241. private void colorsFormUserPrimaryColorChanged(object sender, ColorEventArgs ce)
  242. {
  243. }
  244. /// <summary>
  245. /// panel1画板点击
  246. /// </summary>
  247. /// <param name="sender"></param>
  248. /// <param name="e"></param>
  249. private void panel1_Click(object sender, EventArgs e)
  250. {
  251. this.colorsForm1.UserPrimaryColor = ColorBgra.FromColor(this.panel1.BackColor);
  252. this.colorsForm1.setSaveBtn_Click(new System.EventHandler(this.panel1Changed));
  253. this.colorsForm1.ShowDialog();
  254. }
  255. private void panel1Changed(object sender, EventArgs e)
  256. {
  257. this.panel1.BackColor = this.colorsForm1.UserPrimaryColor.ToColor();
  258. this.colorsForm1.Close();
  259. }
  260. /// <summary>
  261. /// panel2画板点击
  262. /// </summary>
  263. /// <param name="sender"></param>
  264. /// <param name="e"></param>
  265. private void panel2_Click(object sender, EventArgs e)
  266. {
  267. this.colorsForm2.UserPrimaryColor = ColorBgra.FromColor(this.panel2.BackColor);
  268. this.colorsForm2.setSaveBtn_Click(new System.EventHandler(this.panel2Changed));
  269. this.colorsForm2.ShowDialog();
  270. }
  271. private void panel2Changed(object sender, EventArgs e)
  272. {
  273. this.panel2.BackColor = this.colorsForm2.UserPrimaryColor.ToColor();
  274. this.colorsForm2.Close();
  275. }
  276. /// <summary>
  277. /// panel3 画板点击
  278. /// </summary>
  279. /// <param name="sender"></param>
  280. /// <param name="e"></param>
  281. private void panel3_Click(object sender, EventArgs e)
  282. {
  283. this.colorsForm3.UserPrimaryColor = ColorBgra.FromColor(this.panel3.BackColor);
  284. this.colorsForm3.setSaveBtn_Click(new System.EventHandler(this.panel3Changed));
  285. this.colorsForm3.ShowDialog();
  286. }
  287. private void panel3Changed(object sender, EventArgs e)
  288. {
  289. this.panel3.BackColor = this.colorsForm3.UserPrimaryColor.ToColor();
  290. this.colorsForm3.Close();
  291. }
  292. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  293. {
  294. }
  295. private void numericUpDown2_ValueChanged(object sender, EventArgs e)
  296. {
  297. }
  298. private void numericUpDown1_ValueChanged(object sender, EventArgs e)
  299. {
  300. }
  301. }
  302. }