BorderEditorForm.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. using FastReport.Controls;
  2. using FastReport.Utils;
  3. using System;
  4. using System.Drawing;
  5. using System.Windows.Forms;
  6. namespace FastReport.Forms
  7. {
  8. internal partial class BorderEditorForm : BaseDialogForm
  9. {
  10. private Border border;
  11. private bool changed;
  12. public Border Border
  13. {
  14. get { return border; }
  15. set
  16. {
  17. border = value;
  18. pnSample.Border = value;
  19. UpdateBorder();
  20. UpdateControls();
  21. }
  22. }
  23. public bool Changed
  24. {
  25. get { return changed; }
  26. set { changed = value; }
  27. }
  28. private LineStyle LineStyle
  29. {
  30. get { return lsLineStyle.Style; }
  31. }
  32. private float LineWidth
  33. {
  34. get { return cbxLineWidth.LineWidth; }
  35. }
  36. private Color LineColor
  37. {
  38. get { return cbxLineColor.Color; }
  39. }
  40. private void Change()
  41. {
  42. changed = true;
  43. UpdateControls();
  44. }
  45. private void UpdateBorder()
  46. {
  47. cbxLineWidth.LineWidth = Border.Width;
  48. cbxLineColor.Color = Border.Color;
  49. lsLineStyle.Style = Border.Style;
  50. lsLineStyle.LineColor = Border.Color;
  51. lsLineStyle.LineWidth = Border.Width;
  52. cbShadow.Checked = Border.Shadow;
  53. cbxShadowWidth.LineWidth = Border.ShadowWidth;
  54. cbxShadowColor.Color = Border.ShadowColor;
  55. }
  56. private void Line_Click(object sender, EventArgs e)
  57. {
  58. BorderLines line = BorderLines.None;
  59. if (sender == cbTopLine)
  60. line = BorderLines.Top;
  61. else if (sender == cbBottomLine)
  62. line = BorderLines.Bottom;
  63. else if (sender == cbLeftLine)
  64. line = BorderLines.Left;
  65. else if (sender == cbRightLine)
  66. line = BorderLines.Right;
  67. ToggleLine(line, (sender as CheckBox).Checked);
  68. }
  69. private void btnNoLines_Click(object sender, EventArgs e)
  70. {
  71. Border.Lines = BorderLines.None;
  72. Change();
  73. }
  74. private void btnAllLines_Click(object sender, EventArgs e)
  75. {
  76. Border.Lines = BorderLines.All;
  77. Border.Style = LineStyle;
  78. Border.Width = LineWidth;
  79. Border.Color = LineColor;
  80. Change();
  81. }
  82. private void cbShadow_CheckedChanged(object sender, EventArgs e)
  83. {
  84. Border.Shadow = cbShadow.Checked;
  85. Change();
  86. }
  87. private void cbxShadowColor_ColorSelected(object sender, EventArgs e)
  88. {
  89. Border.ShadowColor = cbxShadowColor.Color;
  90. Change();
  91. }
  92. private void cbxShadowWidth_WidthSelected(object sender, EventArgs e)
  93. {
  94. if (cbxShadowWidth.LineWidth == 0) return;
  95. Border.ShadowWidth = cbxShadowWidth.LineWidth;
  96. Change();
  97. }
  98. private void cbxLineColor_ColorSelected(object sender, EventArgs e)
  99. {
  100. lsLineStyle.LineColor = LineColor;
  101. }
  102. private void cbxLineWidth_WidthSelected(object sender, EventArgs e)
  103. {
  104. lsLineStyle.LineWidth = LineWidth;
  105. }
  106. public void ToggleLine(BorderLines line, bool state)
  107. {
  108. BorderLine line1 = null;
  109. switch (line)
  110. {
  111. case BorderLines.Top:
  112. line1 = Border.TopLine;
  113. break;
  114. case BorderLines.Bottom:
  115. line1 = Border.BottomLine;
  116. break;
  117. case BorderLines.Left:
  118. line1 = Border.LeftLine;
  119. break;
  120. case BorderLines.Right:
  121. line1 = Border.RightLine;
  122. break;
  123. }
  124. if (line1 != null)
  125. {
  126. if (state || (line1.Style != LineStyle || line1.Width != LineWidth || line1.Color != LineColor))
  127. {
  128. Border.Lines = Border.Lines | line;
  129. line1.Style = LineStyle;
  130. line1.Width = LineWidth;
  131. line1.Color = LineColor;
  132. }
  133. else
  134. {
  135. Border.Lines = Border.Lines & ~line;
  136. }
  137. }
  138. Change();
  139. }
  140. private void pnSample_ToggleLine(object sender, ToggleLineEventArgs e)
  141. {
  142. ToggleLine(e.Line, e.Toggle);
  143. }
  144. private void btnOk_Click(object sender, EventArgs e)
  145. {
  146. Border.ShadowWidth = cbxShadowWidth.LineWidth;
  147. }
  148. public void UpdateControls()
  149. {
  150. cbTopLine.Checked = (Border.Lines & BorderLines.Top) != 0;
  151. cbBottomLine.Checked = (Border.Lines & BorderLines.Bottom) != 0;
  152. cbLeftLine.Checked = (Border.Lines & BorderLines.Left) != 0;
  153. cbRightLine.Checked = (Border.Lines & BorderLines.Right) != 0;
  154. cbShadow.Checked = Border.Shadow;
  155. cbxShadowWidth.LineWidth = Border.ShadowWidth;
  156. cbxShadowColor.Color = Border.ShadowColor;
  157. lblShadowWidth.Enabled = Border.Shadow;
  158. cbxShadowWidth.Enabled = Border.Shadow;
  159. lblShadowColor.Enabled = Border.Shadow;
  160. cbxShadowColor.Enabled = Border.Shadow;
  161. pnSample.Refresh();
  162. }
  163. public override void Localize()
  164. {
  165. base.Localize();
  166. MyRes res = new MyRes("Forms,Border");
  167. Text = res.Get("");
  168. gbBorder.Text = res.Get("Border");
  169. gbLine.Text = res.Get("Line");
  170. lblHint.Text = res.Get("Hint");
  171. cbShadow.Text = res.Get("Shadow");
  172. lblShadowWidth.Text = res.Get("Width");
  173. lblShadowColor.Text = res.Get("Color");
  174. lblStyle.Text = res.Get("Style");
  175. lblLineWidth.Text = res.Get("Width");
  176. lblLineColor.Text = res.Get("Color");
  177. }
  178. public override void UpdateDpiDependencies()
  179. {
  180. base.UpdateDpiDependencies();
  181. btnAllLines.Image = GetImage(36);
  182. btnNoLines.Image = GetImage(37);
  183. cbTopLine.Image = GetImage(32);
  184. cbBottomLine.Image = GetImage(33);
  185. cbLeftLine.Image = GetImage(34);
  186. cbRightLine.Image = GetImage(35);
  187. lblShadow.Left = cbShadow.Right + this.LogicalToDevice(4);
  188. lblShadow.Width = pnSample.Right - lblShadow.Left;
  189. }
  190. public BorderEditorForm()
  191. {
  192. InitializeComponent();
  193. Border = new Border();
  194. Border.Lines = BorderLines.All;
  195. pnSample.Border = Border;
  196. changed = false;
  197. Localize();
  198. UIUtils.CheckRTL(this);
  199. UpdateDpiDependencies();
  200. }
  201. }
  202. }