Image.cs 2.1 KB

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