LabelTextControl.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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(0, 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(0, 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(0, 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(0, 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(0, 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(0, 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.Maximum = new decimal(new int[] {
  205. 49000,
  206. 0,
  207. 0,
  208. 0});
  209. this.numericUpDown2.Minimum = new decimal(new int[] {
  210. 1,
  211. 0,
  212. 0,
  213. 0});
  214. this.numericUpDown2.Name = "numericUpDown2";
  215. this.numericUpDown2.Size = new System.Drawing.Size(140, 21);
  216. this.numericUpDown2.TabIndex = 12;
  217. this.numericUpDown2.Value = new decimal(new int[] {
  218. 1,
  219. 0,
  220. 0,
  221. 0});
  222. this.numericUpDown2.ValueChanged += new System.EventHandler(this.numericUpDown2_ValueChanged);
  223. //
  224. // LabelTextControl
  225. //
  226. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
  227. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  228. this.Controls.Add(this.numericUpDown2);
  229. this.Controls.Add(this.numericUpDown1);
  230. this.Controls.Add(this.panel3);
  231. this.Controls.Add(this.label6);
  232. this.Controls.Add(this.label5);
  233. this.Controls.Add(this.panel2);
  234. this.Controls.Add(this.label4);
  235. this.Controls.Add(this.panel1);
  236. this.Controls.Add(this.label3);
  237. this.Controls.Add(this.label2);
  238. this.Controls.Add(this.comboBox1);
  239. this.Controls.Add(this.label1);
  240. this.Name = "LabelTextControl";
  241. this.Size = new System.Drawing.Size(239, 205);
  242. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
  243. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit();
  244. this.ResumeLayout(false);
  245. this.PerformLayout();
  246. this.colorsForm1 = new ColorsForm();
  247. this.colorsForm1.StartPosition = FormStartPosition.CenterScreen;
  248. this.colorsForm1.UserPrimaryColorChanged += new ColorEventHandler(this.colorsFormUserPrimaryColorChanged);
  249. this.colorsForm2 = new ColorsForm();
  250. this.colorsForm2.StartPosition = FormStartPosition.CenterScreen;
  251. this.colorsForm2.UserPrimaryColorChanged += new ColorEventHandler(this.colorsFormUserPrimaryColorChanged);
  252. this.colorsForm3 = new ColorsForm();
  253. this.colorsForm3.StartPosition = FormStartPosition.CenterScreen;
  254. this.colorsForm3.UserPrimaryColorChanged += new ColorEventHandler(this.colorsFormUserPrimaryColorChanged);
  255. }
  256. private void colorsFormUserPrimaryColorChanged(object sender, ColorEventArgs ce)
  257. {
  258. }
  259. /// <summary>
  260. /// panel1画板点击
  261. /// </summary>
  262. /// <param name="sender"></param>
  263. /// <param name="e"></param>
  264. private void panel1_Click(object sender, EventArgs e)
  265. {
  266. this.colorsForm1.UserPrimaryColor = ColorBgra.FromColor(this.panel1.BackColor);
  267. this.colorsForm1.setSaveBtn_Click(new System.EventHandler(this.panel1Changed));
  268. this.colorsForm1.ShowDialog();
  269. }
  270. private void panel1Changed(object sender, EventArgs e)
  271. {
  272. this.panel1.BackColor = this.colorsForm1.UserPrimaryColor.ToColor();
  273. this.colorsForm1.Close();
  274. }
  275. /// <summary>
  276. /// panel2画板点击
  277. /// </summary>
  278. /// <param name="sender"></param>
  279. /// <param name="e"></param>
  280. private void panel2_Click(object sender, EventArgs e)
  281. {
  282. this.colorsForm2.UserPrimaryColor = ColorBgra.FromColor(this.panel2.BackColor);
  283. this.colorsForm2.setSaveBtn_Click(new System.EventHandler(this.panel2Changed));
  284. this.colorsForm2.ShowDialog();
  285. }
  286. private void panel2Changed(object sender, EventArgs e)
  287. {
  288. this.panel2.BackColor = this.colorsForm2.UserPrimaryColor.ToColor();
  289. this.colorsForm2.Close();
  290. }
  291. /// <summary>
  292. /// panel3 画板点击
  293. /// </summary>
  294. /// <param name="sender"></param>
  295. /// <param name="e"></param>
  296. private void panel3_Click(object sender, EventArgs e)
  297. {
  298. this.colorsForm3.UserPrimaryColor = ColorBgra.FromColor(this.panel3.BackColor);
  299. this.colorsForm3.setSaveBtn_Click(new System.EventHandler(this.panel3Changed));
  300. this.colorsForm3.ShowDialog();
  301. }
  302. private void panel3Changed(object sender, EventArgs e)
  303. {
  304. this.panel3.BackColor = this.colorsForm3.UserPrimaryColor.ToColor();
  305. this.colorsForm3.Close();
  306. }
  307. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  308. {
  309. }
  310. private void numericUpDown2_ValueChanged(object sender, EventArgs e)
  311. {
  312. }
  313. private void numericUpDown1_ValueChanged(object sender, EventArgs e)
  314. {
  315. }
  316. }
  317. }