GaugeEditorForm.cs 8.3 KB

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