LabelEditor.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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.Radial;
  7. using FastReport.Gauge.Simple.Progress;
  8. namespace FastReport.TypeEditors
  9. {
  10. /// <summary>
  11. /// Provides a user interface for editing an expression.
  12. /// </summary>
  13. internal class LabelEditor : UITypeEditor
  14. {
  15. /// <summary>
  16. ///
  17. /// </summary>
  18. protected GaugeObject gauge;
  19. /// <summary>
  20. ///
  21. /// </summary>
  22. protected GaugeEditorForm gaugeEditor;
  23. internal LabelEditor() : base()
  24. {
  25. gauge = new GaugeObject();
  26. gaugeEditor = new GaugeEditorForm(gauge);
  27. }
  28. private void SetLabel(GaugeLabel label)
  29. {
  30. if (label is SimpleProgressLabel)
  31. {
  32. gauge = label.Parent as SimpleProgressGauge;
  33. gaugeEditor = new SimpleProgressGaugeEditorForm((SimpleProgressGauge)gauge);
  34. }
  35. else if (label is RadialLabel)
  36. {
  37. gauge = label.Parent as RadialGauge;
  38. gaugeEditor = new RadialGaugeEditorForm((RadialGauge)gauge);
  39. }
  40. gaugeEditor.pageControl1.ActivePage = (Panel)gaugeEditor.pageControl1.Pages.Find("pgLabel", false)[0];
  41. }
  42. /// <inheritdoc/>
  43. public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
  44. {
  45. return UITypeEditorEditStyle.Modal;
  46. }
  47. /// <inheritdoc/>
  48. public override object EditValue(ITypeDescriptorContext context,
  49. IServiceProvider provider, object Value)
  50. {
  51. GaugeLabel label = (GaugeLabel)Value;
  52. Report report = context != null && context.Instance is Base ? (context.Instance as Base).Report : null;
  53. if (report != null)
  54. {
  55. SetLabel(label);
  56. gauge.InvokeEditor(gaugeEditor);
  57. return gauge.Label;
  58. }
  59. return Value;
  60. }
  61. }
  62. }