Image.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /**
  2. * Namespace: System.Web.UI.WebControls
  3. * Class: Image
  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 (2001)
  12. */
  13. using System;
  14. using System.Web;
  15. using System.Web.UI;
  16. using System.ComponentModel;
  17. namespace System.Web.UI.WebControls
  18. {
  19. [DefaultProperty("ImageUrl")]
  20. [ParseChildrenAttribute(false)]
  21. public class Image : WebControl
  22. {
  23. public Image(): base(HtmlTextWriterTag.Img)
  24. {
  25. }
  26. public virtual string AlternateText
  27. {
  28. get
  29. {
  30. object o = ViewState["AlternateText"];
  31. if(o!=null)
  32. return (string)o;
  33. return String.Empty;
  34. }
  35. set
  36. {
  37. ViewState["AlternateText"] = value;
  38. }
  39. }
  40. public override bool Enabled
  41. {
  42. get
  43. {
  44. return base.Enabled;
  45. }
  46. set
  47. {
  48. base.Enabled = value;
  49. }
  50. }
  51. public override FontInfo Font
  52. {
  53. get
  54. {
  55. return base.Font;
  56. }
  57. }
  58. public virtual ImageAlign ImageAlign
  59. {
  60. get
  61. {
  62. object o = ViewState["ImageAlign"];
  63. if(o!=null)
  64. return (ImageAlign)o;
  65. return ImageAlign.NotSet;
  66. }
  67. set
  68. {
  69. ViewState["ImageAlign"] = value;
  70. }
  71. }
  72. public virtual string ImageUrl
  73. {
  74. get
  75. {
  76. object o = ViewState["ImageUrl"];
  77. if(o!=null)
  78. return (string)o;
  79. return String.Empty;
  80. }
  81. set
  82. {
  83. ViewState["ImageUrl"] = value;
  84. }
  85. }
  86. protected override void AddAttributesToRender(HtmlTextWriter writer)
  87. {
  88. base.AddAttributesToRender(writer);
  89. if(ImageUrl.Length > 0)
  90. {
  91. writer.AddAttribute(HtmlTextWriterAttribute.Src, ResolveUrl(ImageUrl));
  92. }
  93. if(AlternateText.Length > 0)
  94. {
  95. writer.AddAttribute(HtmlTextWriterAttribute.Alt, AlternateText);
  96. }
  97. if(BorderWidth.IsEmpty)
  98. {
  99. writer.AddAttribute(HtmlTextWriterAttribute.Border, "0");
  100. }
  101. if(ImageAlign != ImageAlign.NotSet)
  102. {
  103. writer.AddAttribute(HtmlTextWriterAttribute.Align, Enum.Format(typeof(ImageAlign), ImageAlign, "G"));
  104. }
  105. }
  106. protected override void RenderContents(HtmlTextWriter writer)
  107. {
  108. }
  109. }
  110. }