GaugeEditorForm.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. using System;
  2. using FastReport.Utils;
  3. using FastReport.Forms;
  4. using System.Windows.Forms;
  5. using System.Drawing;
  6. namespace FastReport.Gauge
  7. {
  8. internal enum GaugeEditorPage
  9. {
  10. Scale,
  11. Pointer,
  12. Label
  13. }
  14. internal partial class GaugeEditorForm : BaseDialogForm
  15. {
  16. #region Fields
  17. GaugeObject gauge;
  18. private bool deleteLabel;
  19. #endregion // Fields
  20. #region Properties
  21. internal GaugeObject Gauge { get { return gauge; } }
  22. internal bool DeleteLabel { set { deleteLabel = value; } }
  23. internal GaugeEditorPage ActivePage
  24. {
  25. set
  26. {
  27. if (value == GaugeEditorPage.Scale)
  28. pageControl1.ActivePage = pgScale;
  29. else if (value == GaugeEditorPage.Pointer)
  30. pageControl1.ActivePage = pgPointer;
  31. else if (value == GaugeEditorPage.Label)
  32. pageControl1.ActivePage = pgLabel;
  33. }
  34. }
  35. #endregion // Properties
  36. #region Constructors
  37. public GaugeEditorForm(GaugeObject gauge) : base()
  38. {
  39. deleteLabel = false;
  40. this.gauge = gauge;
  41. InitializeComponent();
  42. Init();
  43. Localize();
  44. }
  45. #endregion //Constructors
  46. #region Protected Methods
  47. protected virtual void Init()
  48. {
  49. if (deleteLabel)
  50. pageControl1.Pages.Remove(pgLabel);
  51. if (gauge != null)
  52. {
  53. numericUpDowMajorWidth.Value = gauge.Scale.MajorTicks.Width;
  54. cbxMajorTicksColor.Color = gauge.Scale.MajorTicks.Color;
  55. numericUpDowMinorWidth.Value = gauge.Scale.MinorTicks.Width;
  56. cbxMinorTicksColor.Color = gauge.Scale.MinorTicks.Color;
  57. textBoxButtonScaleFont.Text = gauge.Scale.Font.FontFamily.Name + ", " + gauge.Scale.Font.SizeInPoints + "pt";
  58. if (gauge.Scale.Font.Style != FontStyle.Regular)
  59. textBoxButtonScaleFont.Text += ", style=" + gauge.Scale.Font.Style.ToString();
  60. cbxPointerBorderColor.Color = gauge.Pointer.BorderColor;
  61. if (pgLabel != null)
  62. {
  63. textBoxButtonLabelFont.Text = gauge.Label.Font.FontFamily.Name + ", " + gauge.Label.Font.SizeInPoints + "pt";
  64. if (gauge.Label.Font.Style != FontStyle.Regular)
  65. textBoxButtonLabelFont.Text += ", style=" + gauge.Label.Font.Style.ToString();
  66. cbLabelColor.Color = gauge.Label.Color;
  67. tbLabelText.Text = gauge.Label.Text;
  68. }
  69. }
  70. }
  71. public override void UpdateDpiDependencies()
  72. {
  73. base.UpdateDpiDependencies();
  74. textBoxButtonScaleFont.Image = GetImage(59);
  75. textBoxButtonLabelFont.Image = GetImage(59);
  76. }
  77. #endregion // Protected Methods
  78. #region Public Methods
  79. public override void Localize()
  80. {
  81. base.Localize();
  82. MyRes res = new MyRes("Objects,Gauge,GaugeForms,PageGeneral");
  83. pgGeneral.Text = res.Get("");
  84. btnExpression.Text = res.Get("Expression");
  85. btnGeneralBorder.Text = res.Get("Border");
  86. btnGeneralFill.Text = res.Get("Fill");
  87. res = new MyRes("Objects,Gauge,GaugeForms,PageScale");
  88. pgScale.Text = res.Get("");
  89. res = new MyRes("Objects,Gauge,GaugeForms,PageScale,TabTicks");
  90. tabControl3.TabPages[0].Text = res.Get("");
  91. gpBoxMjr.Text = res.Get("MajorTicks");
  92. lblWidthMjr.Text = res.Get("MajorTicks,Width");
  93. lblColorMjr.Text = res.Get("MajorTicks,Color");
  94. gpBoxMnr.Text = res.Get("MinorTicks");
  95. lblWidthMnr.Text = res.Get("MinorTicks,Width");
  96. lblColorMnr.Text = res.Get("MinorTicks,Color");
  97. res = new MyRes("Objects,Gauge,GaugeForms,PageScale,TabText");
  98. tabControl3.TabPages[1].Text = res.Get("");
  99. lblScaleFont.Text = res.Get("Font");
  100. buttonFill.Text = res.Get("TextFill");
  101. res = new MyRes("Objects,Gauge,GaugeForms,PagePointer");
  102. pgPointer.Text = res.Get("");
  103. lblPtrBorderColor.Text = res.Get("BorderColor");
  104. btnPointerFill.Text = res.Get("PointerFill");
  105. res = new MyRes("Objects,Gauge,GaugeForms,PageLabel");
  106. pgLabel.Text = res.Get("");
  107. lblLblColor.Text = res.Get("LabelColor");
  108. lblLabelFont.Text = res.Get("Font");
  109. lblLabelText.Text = res.Get("Text");
  110. }
  111. #endregion // Public Methods
  112. #region Events Handlers
  113. protected virtual void GaugeEditorForm_FormClosing(object sender, System.Windows.Forms.FormClosingEventArgs e)
  114. {
  115. if (this.DialogResult == DialogResult.OK)
  116. try
  117. {
  118. gauge.Scale.MajorTicks.Width = (int)numericUpDowMajorWidth.Value;
  119. gauge.Scale.MajorTicks.Color = cbxMajorTicksColor.Color;
  120. gauge.Scale.MinorTicks.Width = (int)numericUpDowMinorWidth.Value;
  121. gauge.Scale.MinorTicks.Color = cbxMinorTicksColor.Color;
  122. gauge.Pointer.BorderColor = cbxPointerBorderColor.Color;
  123. if (pgLabel != null)
  124. {
  125. gauge.Label.Color = cbLabelColor.Color;
  126. gauge.Label.Text = tbLabelText.Text;
  127. }
  128. }
  129. catch (Exception ex)
  130. {
  131. if (!Config.WebMode)
  132. {
  133. FRMessageBox.Error(ex.Message);
  134. }
  135. }
  136. }
  137. private void buttonFill_Click(object sender, EventArgs e)
  138. {
  139. using (FillEditorForm form = new FillEditorForm())
  140. {
  141. form.Fill = gauge.Scale.TextFill;
  142. if (form.ShowDialog() == DialogResult.OK)
  143. gauge.Scale.TextFill = form.Fill;
  144. }
  145. }
  146. private void textBoxButtonScaleFont_ButtonClick(object sender, EventArgs e)
  147. {
  148. using (FontDialog dialog = new FontDialog())
  149. {
  150. dialog.Font = gauge.Scale.Font;
  151. if (dialog.ShowDialog() == DialogResult.OK)
  152. {
  153. dialog.Font = new Font(dialog.Font.FontFamily, (float)Math.Round(dialog.Font.Size), dialog.Font.Style);
  154. textBoxButtonScaleFont.Text = Converter.ToString(dialog.Font);
  155. gauge.Scale.Font = dialog.Font;
  156. }
  157. }
  158. }
  159. private void btnPointerFill_Click(object sender, EventArgs e)
  160. {
  161. using (FillEditorForm form = new FillEditorForm())
  162. {
  163. form.Fill = gauge.Pointer.Fill;
  164. if (form.ShowDialog() == DialogResult.OK)
  165. gauge.Pointer.Fill = form.Fill;
  166. }
  167. }
  168. private void btnGeneralBorder_Click(object sender, EventArgs e)
  169. {
  170. using (BorderEditorForm form = new BorderEditorForm())
  171. {
  172. form.Border = gauge.Border;
  173. if (form.ShowDialog() == DialogResult.OK)
  174. gauge.Border = form.Border;
  175. }
  176. }
  177. private void btnGeneralFill_Click(object sender, EventArgs e)
  178. {
  179. using (FillEditorForm form = new FillEditorForm())
  180. {
  181. form.Fill = gauge.Fill;
  182. if (form.ShowDialog() == DialogResult.OK)
  183. gauge.Fill = form.Fill;
  184. }
  185. }
  186. private void textBoxButtonLabelFont_ButtonClick(object sender, EventArgs e)
  187. {
  188. using (FontDialog dialog = new FontDialog())
  189. {
  190. dialog.Font = gauge.Label.Font;
  191. if (dialog.ShowDialog() == DialogResult.OK)
  192. {
  193. dialog.Font = new Font(dialog.Font.FontFamily, (float)Math.Round(dialog.Font.Size), dialog.Font.Style);
  194. textBoxButtonLabelFont.Text = Converter.ToString(dialog.Font);
  195. gauge.Label.Font = dialog.Font;
  196. }
  197. }
  198. }
  199. private void btnExpression_Click(object sender, EventArgs e)
  200. {
  201. using (ExpressionEditorForm expressionForm = new ExpressionEditorForm(Gauge.Report))
  202. {
  203. expressionForm.ExpressionText = gauge.Expression;
  204. if (expressionForm.ShowDialog() == DialogResult.OK)
  205. {
  206. gauge.Expression = expressionForm.ExpressionText;
  207. }
  208. }
  209. }
  210. #endregion // Events Handlers
  211. }
  212. }