Panel.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /**
  2. * Namespace: System.Web.UI.WebControls
  3. * Class: Panel
  4. *
  5. * Author: Gaurav Vaish
  6. * Maintainer: [email protected]
  7. * Contact: <[email protected]>, <[email protected]>
  8. * Implementation: yes
  9. * Status: 100%
  10. *
  11. * (C) Gaurav Vaish (2002)
  12. */
  13. using System;
  14. using System.ComponentModel;
  15. using System.Web;
  16. using System.Web.UI;
  17. namespace System.Web.UI.WebControls
  18. {
  19. //[Designer("??")]
  20. [DefaultProperty("ID")]
  21. [ParseChildren(false)]
  22. [PersistChildren(true)]
  23. [ToolboxData("<{0}:Panel runat=\"server\">Panel</{0}:Panel>")]
  24. public class Panel: WebControl
  25. {
  26. public Panel(): base(HtmlTextWriterTag.Div)
  27. {
  28. }
  29. public virtual string BackImageUrl
  30. {
  31. get
  32. {
  33. object o = ViewState["BackImageUrl"];
  34. if(o != null)
  35. return (string)o;
  36. return String.Empty;
  37. }
  38. set
  39. {
  40. ViewState["BackImageUrl"] = value;
  41. }
  42. }
  43. public virtual HorizontalAlign HorizontalAlign
  44. {
  45. get
  46. {
  47. object o = ViewState["HorizontalAlign"];
  48. if(o != null)
  49. return (HorizontalAlign)o;
  50. return HorizontalAlign.NotSet;
  51. }
  52. set
  53. {
  54. if(!Enum.IsDefined(typeof(HorizontalAlign), value))
  55. {
  56. throw new ArgumentException();
  57. }
  58. ViewState["HorizontalAlign"] = value;
  59. }
  60. }
  61. public virtual bool Wrap
  62. {
  63. get
  64. {
  65. object o = ViewState["Wrap"];
  66. if(o != null)
  67. return (bool)o;
  68. return true;
  69. }
  70. set
  71. {
  72. ViewState["Wrap"] = value;
  73. }
  74. }
  75. protected override void AddAttributesToRender(HtmlTextWriter writer)
  76. {
  77. base.AddAttributesToRender(writer);
  78. if(BackImageUrl.Length > 0)
  79. {
  80. writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundImage, "url(" + ResolveUrl(BackImageUrl) + ")");
  81. }
  82. if(HorizontalAlign != HorizontalAlign.NotSet)
  83. {
  84. writer.AddAttribute(HtmlTextWriterAttribute.Align, TypeDescriptor.GetConverter(typeof(HorizontalAlign)).ConvertToString(HorizontalAlign));
  85. }
  86. if(Wrap)
  87. {
  88. writer.AddAttribute(HtmlTextWriterAttribute.Nowrap, "nowrap");
  89. }
  90. }
  91. }
  92. }