ScaleEditor.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System;
  2. using System.Drawing.Design;
  3. using System.ComponentModel;
  4. using System.Windows.Forms;
  5. using FastReport.Gauge;
  6. using FastReport.Gauge.Linear;
  7. using FastReport.Gauge.Simple;
  8. using FastReport.Gauge.Radial;
  9. namespace FastReport.TypeEditors
  10. {
  11. internal class ScaleEditor : UITypeEditor
  12. {
  13. /// <summary>
  14. ///
  15. /// </summary>
  16. protected GaugeObject gauge;
  17. /// <summary>
  18. ///
  19. /// </summary>
  20. protected GaugeEditorForm gaugeEditor;
  21. internal ScaleEditor() : base()
  22. {
  23. gauge = new GaugeObject();
  24. gaugeEditor = new GaugeEditorForm(gauge);
  25. }
  26. private void SetScale(GaugeScale scale)
  27. {
  28. if (scale is LinearScale)
  29. {
  30. gauge = scale.Parent as LinearGauge;
  31. gaugeEditor = new LinearGaugeEditorForm((LinearGauge)gauge);
  32. }
  33. else if (scale is SimpleScale)
  34. {
  35. gauge = scale.Parent as SimpleGauge;
  36. gaugeEditor = new SimpleGaugeEditorForm((SimpleGauge)gauge);
  37. }
  38. else if (scale is RadialScale)
  39. {
  40. gauge = scale.Parent as RadialGauge;
  41. gaugeEditor = new RadialGaugeEditorForm((RadialGauge)gauge);
  42. }
  43. gaugeEditor.pageControl1.ActivePage = (Panel)gaugeEditor.pageControl1.Pages.Find("pgScale", false)[0];
  44. }
  45. /// <inheritdoc/>
  46. public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
  47. {
  48. return UITypeEditorEditStyle.Modal;
  49. }
  50. /// <inheritdoc/>
  51. public override object EditValue(ITypeDescriptorContext context,
  52. IServiceProvider provider, object Value)
  53. {
  54. GaugeScale scale = (GaugeScale)Value;
  55. Report report = context != null && context.Instance is Base ? (context.Instance as Base).Report : null;
  56. if (report != null)
  57. {
  58. SetScale(scale);
  59. gauge.InvokeEditor(gaugeEditor);
  60. return gaugeEditor.Gauge.Scale;
  61. }
  62. return Value;
  63. }
  64. }
  65. }