UserFormCommandDesigner.cs
上传用户:husern
上传日期:2022-03-24
资源大小:534k
文件大小:3k
源码类别:

编辑器/阅读器

开发平台:

C#

  1. // -- FILE ------------------------------------------------------------------
  2. // name       : UserFormCommandDesigner.cs
  3. // project    : Itenso Web User Forms
  4. // created    : Jani Giannoudis - 2008.10.30
  5. // language   : c#
  6. // environment: .NET 2.0
  7. // copyright  : (c) 2008 by Itenso GmbH, Switzerland
  8. // --------------------------------------------------------------------------
  9. using System;
  10. using System.IO;
  11. using System.Text;
  12. using System.Web.UI;
  13. using System.Web.UI.WebControls;
  14. using System.Web.UI.Design;
  15. using System.Drawing;
  16. namespace Itenso.WebUserForms.Controls
  17. {
  18. // ------------------------------------------------------------------------
  19. public class UserFormCommandDesigner : ControlDesigner
  20. {
  21. // ----------------------------------------------------------------------
  22. public UserFormCommandDesigner()
  23. {
  24. } // UserFormCommandDesigner
  25. // ----------------------------------------------------------------------
  26. protected Control DesignControl
  27. {
  28. get { return base.Component as Control; }
  29. } // DesignControl
  30. // ----------------------------------------------------------------------
  31. protected Color MissingCommandNameColor
  32. {
  33. get { return this.missingCommandNameColor; }
  34. set { this.missingCommandNameColor = value; }
  35. } // MissingCommandNameColor
  36. // ----------------------------------------------------------------------
  37. protected string CommandName
  38. {
  39. get
  40. {
  41. IUserFormCommand formCommand = base.Component as IUserFormCommand;
  42. if ( formCommand == null )
  43. {
  44. throw new InvalidOperationException( "IUserFormCommand required" );
  45. }
  46. return formCommand.CommandName;
  47. }
  48. } // CommandName
  49. // ----------------------------------------------------------------------
  50. protected bool HasCommandName
  51. {
  52. get { return !string.IsNullOrEmpty( CommandName ); }
  53. } // HasCommandName
  54. // ----------------------------------------------------------------------
  55. public override string GetDesignTimeHtml()
  56. {
  57. Control designControl = DesignControl;
  58. if ( designControl == null )
  59. {
  60. return base.GetDesignTimeHtml();
  61. }
  62. WebControl designWebControl = designControl as WebControl;
  63. if ( designWebControl != null )
  64. {
  65. designWebControl.BackColor = GetStatusColor();
  66. }
  67. return GetRenderHtml( designControl );
  68. } // GetDesignTimeHtml
  69. // ----------------------------------------------------------------------
  70. protected virtual Color GetStatusColor()
  71. {
  72. if ( !HasCommandName )
  73. {
  74. return MissingCommandNameColor;
  75. }
  76. return Color.Empty;
  77. } // GetStatusColor
  78. // ----------------------------------------------------------------------
  79. protected virtual string GetRenderHtml( Control control )
  80. {
  81. StringWriter text = new StringWriter();
  82. HtmlTextWriter writer = new HtmlTextWriter( text );
  83. control.RenderControl( writer );
  84. return text.ToString();
  85. } // GetRenderHtml
  86. // ----------------------------------------------------------------------
  87. // members
  88. private Color missingCommandNameColor = Color.Red;
  89. } // class UserFormCommandDesigner
  90. } // namespace Itenso.WebUserForms.Controls
  91. // -- EOF -------------------------------------------------------------------