/// <summary>
        /// 执行插入图像命令
        /// </summary>
        public static void InsertImage(this HtmlDocument document, ImageObject image)
        {
            string hspace = (image.HorizontalSpace > 0 ? "hspace=\"" + image.HorizontalSpace + "\" " : string.Empty);
            string vspace = (image.VerticalSpace > 0 ? "vspace=\"" + image.VerticalSpace + "\" " : string.Empty);
            string border = (image.BorderSize > 0 ? "border=\"" + image.BorderSize + "\" " : string.Empty);
            string align  = (image.Alignment != ImageAlignment.Default ? "align=\"" + image.Alignment.Value + "\" " : string.Empty);
            string title  = (string.IsNullOrEmpty(image.TitleText) == false ? "title=\"" + image.TitleText + "\" " : string.Empty);
            string tx     = string.Empty;

            if (string.IsNullOrEmpty(image.LinkUrl))
            {
                tx = string.Format("<img src=\"{0}\" alt=\"{1}\" width=\"{2}\" height=\"{3}\" {4}{5}{6}{7}{8} />",
                                   image.ImageUrl, image.AltText, image.Width, image.Height, title, hspace, vspace, border, align);
            }
            else
            {
                string url = image.ImageUrl.HtmlEncoding();
                tx = string.Format("<a href=\"{0}\"><img src=\"{1}\" alt=\"{2}\" width=\"{3}\" height=\"{4}\" {5}{6}{7}{8}{9} /></a>",
                                   image.LinkUrl, image.ImageUrl, image.AltText, image.Width, image.Height, title, hspace, vspace, border, align);
            }
            document.InsertHTML(tx);
        }
示例#2
0
 void InitBindingContext()
 {
     Model = new ImageObject
     {
         ImageUrl = "http://",
         Alignment = ImageAlignment.Default
     };
 }
 /// <summary>
 /// 执行插入图像命令
 /// </summary>
 public static void InsertImage(this HtmlDocument document, ImageObject image)
 {
     string hspace = (image.HorizontalSpace > 0 ? "hspace=\"" + image.HorizontalSpace + "\" " : string.Empty);
     string vspace = (image.VerticalSpace > 0 ? "vspace=\"" + image.VerticalSpace + "\" " : string.Empty);
     string border = (image.BorderSize > 0 ? "border=\"" + image.BorderSize + "\" " : string.Empty);
     string align = (image.Alignment != ImageAlignment.Default ? "align=\"" + image.Alignment.Value + "\" " : string.Empty);
     string title = (string.IsNullOrEmpty(image.TitleText) == false ? "title=\"" + image.TitleText + "\" " : string.Empty);
     string tx = string.Empty;
     if (string.IsNullOrEmpty(image.LinkUrl))
     {
         tx = string.Format("<img src=\"{0}\" alt=\"{1}\" width=\"{2}\" height=\"{3}\" {4}{5}{6}{7}{8} />",
             image.ImageUrl, image.AltText, image.Width, image.Height, title, hspace, vspace, border, align);
     }
     else
     {
         string url = image.ImageUrl.HtmlEncoding();
         tx = string.Format("<a href=\"{0}\"><img src=\"{1}\" alt=\"{2}\" width=\"{3}\" height=\"{4}\" {5}{6}{7}{8}{9} /></a>",
             image.LinkUrl, image.ImageUrl, image.AltText, image.Width, image.Height, title, hspace, vspace, border, align);
     }
     document.InsertHTML(tx);
 }