コード例 #1
0
            /// <summary>
            /// Render this control as an HTML stream.
            /// </summary>
            /// <param name="output">The HTML writer to write out to.</param>
            protected override void Render(HtmlTextWriter output)
            {
                // first of all render the bitmap;
                System.Drawing.Bitmap b = new System.Drawing.Bitmap((int)Width.Value, (int)Height.Value);
                if (backColor_ != null)
                {
                    Graphics g = Graphics.FromImage(b);
                    g.FillRectangle((new Pen((Color)backColor_)).Brush, 0, 0, b.Width, b.Height);
                }
                ps_.Draw(Graphics.FromImage(b), new System.Drawing.Rectangle(0, 0, b.Width, b.Height));

                // then store in context memory.
                Context.Session[prefix() + "PNG"] = b;

                // now render html.
                if (BorderStyle == BorderStyle.None)
                {
                    output.AddAttribute("border", "0");
                }
                else
                {
                    output.AddAttribute("border", BorderWidth.ToString());
                    output.AddAttribute("borderColor", BorderColor.ToKnownColor().ToString());
                }
                output.AddAttribute("cellSpacing", "0");
                output.AddAttribute("cellPadding", "0");
                output.RenderBeginTag("table");
                output.RenderBeginTag("tr");
                output.AddAttribute("vAlign", "center");
                output.AddAttribute("align", "middle");
                output.RenderBeginTag("td");
                output.RenderBeginTag("P");
                output.AddAttribute("src", plotUrl);
                output.AddAttribute("alt", ToolTip);
                output.RenderBeginTag("img");
                output.RenderEndTag();
                output.RenderEndTag();
                output.RenderEndTag();
                output.RenderEndTag();
                output.RenderEndTag();
                output.Flush();
            }
コード例 #2
0
        protected override void Render(HtmlTextWriter writer)
        {
            if (null == MyGadget)
            {
                return;
            }

            if (MyGadget is RootElementMaster)
            {
                SetupGadgetForInlineRender((RootElementMaster)MyGadget);
            }
            string bordStyle = "";

            if (BorderWidth.Value > 0)
            {
                string color = BorderColor.IsEmpty ? "" : BorderColor.ToKnownColor().ToString();
                bordStyle = string.Format("border:{0} {1} {2};", BorderWidth.ToString(), BorderStyle.ToString(), color);
            }

            writer.Write("<div");
            if (!string.IsNullOrEmpty(CssClass))
            {
                writer.Write(" class=\"" + CssClass + "\" ");
            }
            if (!string.IsNullOrEmpty(bordStyle) ||
                !Width.IsEmpty ||
                !Height.IsEmpty)
            {
                writer.Write(" style=\"");
                writer.Write(bordStyle);
                if (!Width.IsEmpty)
                {
                    writer.Write(String.Format("width:{0};", Width));
                }
                if (!Height.IsEmpty)
                {
                    writer.Write(String.Format("height:{0};", Height));
                }

                writer.Write("\"");
            }
            writer.WriteLine(">");

            if (MyGadget.HasErrors())
            {
                writer.WriteLine("<pre style='font-weight:bold;color:red;'>");
                writer.WriteLine(MyGadget.Errors.ParseErrors[0].Message);
                if (MyGadget.Errors.ParseErrors[0] is XmlException)
                {
                    string err = MyGadget.Errors.GetParseExceptionContent((XmlException)MyGadget.Errors.ParseErrors[0]);
                    if (!string.IsNullOrEmpty(err))
                    {
                        writer.WriteLine(err.Replace("<", "&lt;").Replace(">", "&gt;"));
                    }
                }
                writer.WriteLine("</pre>");
            }
            else
            {
                MyGadget.Render(writer);
            }
            writer.WriteLine("</div>");
        }