Image.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. //
  2. // System.Web.UI.WebControls.Image.cs
  3. //
  4. // Authors:
  5. // Gaurav Vaish ([email protected])
  6. // Andreas Nahr ([email protected])
  7. //
  8. // (C) Gaurav Vaish (2002)
  9. // (C) 2003 Andreas Nahr
  10. //
  11. //
  12. // Permission is hereby granted, free of charge, to any person obtaining
  13. // a copy of this software and associated documentation files (the
  14. // "Software"), to deal in the Software without restriction, including
  15. // without limitation the rights to use, copy, modify, merge, publish,
  16. // distribute, sublicense, and/or sell copies of the Software, and to
  17. // permit persons to whom the Software is furnished to do so, subject to
  18. // the following conditions:
  19. //
  20. // The above copyright notice and this permission notice shall be
  21. // included in all copies or substantial portions of the Software.
  22. //
  23. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  27. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  28. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  29. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  30. //
  31. using System;
  32. using System.Web;
  33. using System.Web.UI;
  34. using System.ComponentModel;
  35. namespace System.Web.UI.WebControls
  36. {
  37. [DefaultProperty("ImageUrl")]
  38. public class Image : WebControl
  39. {
  40. public Image(): base(HtmlTextWriterTag.Img)
  41. {
  42. }
  43. [DefaultValue (""), Bindable (true), WebCategory ("Appearance")]
  44. [WebSysDescription ("An alternative text that is shown if the image cannot be displayed.")]
  45. public virtual string AlternateText
  46. {
  47. get
  48. {
  49. object o = ViewState["AlternateText"];
  50. if(o!=null)
  51. return (string)o;
  52. return String.Empty;
  53. }
  54. set
  55. {
  56. ViewState["AlternateText"] = value;
  57. }
  58. }
  59. [Browsable (false), EditorBrowsable (EditorBrowsableState.Never)]
  60. public override bool Enabled
  61. {
  62. get
  63. {
  64. return base.Enabled;
  65. }
  66. set
  67. {
  68. base.Enabled = value;
  69. }
  70. }
  71. [Browsable (false), EditorBrowsable (EditorBrowsableState.Never)]
  72. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  73. public override FontInfo Font
  74. {
  75. get
  76. {
  77. return base.Font;
  78. }
  79. }
  80. [DefaultValue (typeof (ImageAlign), "NotSet"), Bindable (true), WebCategory ("Layout")]
  81. [WebSysDescription ("The alignment of the image.")]
  82. public virtual ImageAlign ImageAlign
  83. {
  84. get
  85. {
  86. object o = ViewState["ImageAlign"];
  87. if(o!=null)
  88. return (ImageAlign)o;
  89. return ImageAlign.NotSet;
  90. }
  91. set
  92. {
  93. ViewState["ImageAlign"] = value;
  94. }
  95. }
  96. [DefaultValue (""), Bindable (true), WebCategory ("Appearance")]
  97. [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
  98. [WebSysDescription ("The URL to the image file.")]
  99. public virtual string ImageUrl
  100. {
  101. get
  102. {
  103. object o = ViewState["ImageUrl"];
  104. if(o!=null)
  105. return (string)o;
  106. return String.Empty;
  107. }
  108. set
  109. {
  110. ViewState["ImageUrl"] = value;
  111. }
  112. }
  113. protected override void AddAttributesToRender(HtmlTextWriter writer)
  114. {
  115. base.AddAttributesToRender(writer);
  116. if(ImageUrl.Length > 0)
  117. {
  118. writer.AddAttribute(HtmlTextWriterAttribute.Src, ResolveUrl(ImageUrl));
  119. }
  120. if(AlternateText.Length > 0)
  121. {
  122. writer.AddAttribute(HtmlTextWriterAttribute.Alt, AlternateText);
  123. }
  124. if(BorderWidth.IsEmpty)
  125. {
  126. writer.AddAttribute(HtmlTextWriterAttribute.Border, "0");
  127. }
  128. if(ImageAlign != ImageAlign.NotSet)
  129. {
  130. writer.AddAttribute(HtmlTextWriterAttribute.Align, Enum.Format(typeof(ImageAlign), ImageAlign, "G"));
  131. }
  132. }
  133. protected override void RenderContents(HtmlTextWriter writer)
  134. {
  135. }
  136. }
  137. }