public override void AddAttributesToRender(HtmlTextWriter writer, WebControl owner)
 {
     base.AddAttributesToRender(writer, owner);
     if (!this.Wrap)
     {
         if (this.IsControlEnableLegacyRendering(owner))
         {
             writer.AddAttribute(HtmlTextWriterAttribute.Nowrap, "nowrap");
         }
         else
         {
             writer.AddStyleAttribute(HtmlTextWriterStyle.WhiteSpace, "nowrap");
         }
     }
     System.Web.UI.WebControls.HorizontalAlign horizontalAlign = this.HorizontalAlign;
     if (horizontalAlign != System.Web.UI.WebControls.HorizontalAlign.NotSet)
     {
         TypeConverter converter = TypeDescriptor.GetConverter(typeof(System.Web.UI.WebControls.HorizontalAlign));
         writer.AddAttribute(HtmlTextWriterAttribute.Align, converter.ConvertToString(horizontalAlign).ToLower(CultureInfo.InvariantCulture));
     }
     System.Web.UI.WebControls.VerticalAlign verticalAlign = this.VerticalAlign;
     if (verticalAlign != System.Web.UI.WebControls.VerticalAlign.NotSet)
     {
         TypeConverter converter2 = TypeDescriptor.GetConverter(typeof(System.Web.UI.WebControls.VerticalAlign));
         writer.AddAttribute(HtmlTextWriterAttribute.Valign, converter2.ConvertToString(verticalAlign).ToLower(CultureInfo.InvariantCulture));
     }
 }
Exemple #2
0
        public CHorizontalAlign(System.Web.UI.WebControls.HorizontalAlign webHorizontalAlign)
        {
            switch (webHorizontalAlign)
            {
            case System.Web.UI.WebControls.HorizontalAlign.NotSet:
            case System.Web.UI.WebControls.HorizontalAlign.Justify:
                _value = HorizontalAlign.General;
                break;

            default:
                _value = (HorizontalAlign)((int)webHorizontalAlign);
                break;
            }
        }
        protected override void AddAttributesToRender(HtmlTextWriter writer)
        {
            base.AddAttributesToRender(writer);
            string backImageUrl = this.BackImageUrl;

            if (backImageUrl.Trim().Length > 0)
            {
                writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundImage, "url(" + base.ResolveClientUrl(backImageUrl) + ")");
            }
            this.AddScrollingAttribute(this.ScrollBars, writer);
            System.Web.UI.WebControls.HorizontalAlign horizontalAlign = this.HorizontalAlign;
            if (horizontalAlign != System.Web.UI.WebControls.HorizontalAlign.NotSet)
            {
                TypeConverter converter = TypeDescriptor.GetConverter(typeof(System.Web.UI.WebControls.HorizontalAlign));
                writer.AddStyleAttribute(HtmlTextWriterStyle.TextAlign, converter.ConvertToInvariantString(horizontalAlign).ToLowerInvariant());
            }
            if (!this.Wrap)
            {
                if (base.EnableLegacyRendering)
                {
                    writer.AddAttribute(HtmlTextWriterAttribute.Nowrap, "nowrap", false);
                }
                else
                {
                    writer.AddStyleAttribute(HtmlTextWriterStyle.WhiteSpace, "nowrap");
                }
            }
            if (this.Direction == ContentDirection.LeftToRight)
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Dir, "ltr");
            }
            else if (this.Direction == ContentDirection.RightToLeft)
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Dir, "rtl");
            }
            if (((!base.DesignMode && (this.Page != null)) && ((this.Page.RequestInternal != null) && (this.Page.Request.Browser.EcmaScriptVersion.Major > 0))) && ((this.Page.Request.Browser.W3CDomVersion.Major > 0) && (this.DefaultButton.Length > 0)))
            {
                Control button = this.FindControl(this.DefaultButton);
                if (!(button is IButtonControl))
                {
                    throw new InvalidOperationException(System.Web.SR.GetString("HtmlForm_OnlyIButtonControlCanBeDefaultButton", new object[] { this.ID }));
                }
                this.Page.ClientScript.RegisterDefaultButtonScript(button, writer, true);
            }
        }
        //***************************************************************************
        // Public Methods
        //
        public void ProcessRequest(HttpContext context)
        {
            Exception exKeep = null;
            string
                strW      = context.Request.Params["w"],
                strH      = context.Request.Params["h"],
                strFgClr  = context.Request.Params["fg"],
                strBgClr  = context.Request.Params["bg"],
                strFont   = context.Request.Params["fnt"],
                strSize   = context.Request.Params["sz"],
                strStyle  = context.Request.Params["st"],
                strFormat = context.Request.Params["fmt"],
                strAlign  = context.Request.Params["aln"];

            int iW = 0,
                iH = 0;
            Color
                fgClr = Color.Empty,
                bgClr = Color.Empty,
                tdClr = Color.Empty;
            float
                fSZ    = 0.9f;
            int iFgClr = 0,
                iBgClr = 0,
                iTdClr = 0;
            FontStyle
                style     = FontStyle.Regular;
            int iFntStyle = 0;

            System.Web.UI.WebControls.HorizontalAlign
                align = System.Web.UI.WebControls.HorizontalAlign.NotSet;

            try
            {
                if (!int.TryParse(strW, out iW))
                {
                    context.AddError(new ArgumentException("Specified 'Width' is not a valid integer value."));
                }
                if (!int.TryParse(strH, out iH))
                {
                    context.AddError(new ArgumentException("Specified 'Height' is not a valid integer value."));
                }

                if (string.IsNullOrEmpty(strFormat))
                {
                    strFormat = "hh:MM:ss tt";
                }

                if (!string.IsNullOrEmpty(strFgClr))
                {
                    if (int.TryParse(strFgClr, out iFgClr))
                    {
                        fgClr = Color.FromArgb(iFgClr);
                    }
                    else
                    {
                        fgClr = Color.FromName(strFgClr);
                    }
                }
                else
                {
                    fgClr = Color.Black;
                }
                if (fgClr == null || fgClr == Color.Empty)
                {
                    context.AddError(new ArgumentException("Specified foreground color could not be parsed."));
                }

                if (!string.IsNullOrEmpty(strBgClr))
                {
                    if (int.TryParse(strBgClr, out iBgClr))
                    {
                        bgClr = Color.FromArgb(iBgClr);
                    }
                    else
                    {
                        bgClr = Color.FromName(strBgClr);
                    }
                }
                else
                {
                    bgClr = Color.White;
                }
                if (bgClr == null || bgClr == Color.Empty)
                {
                    context.AddError(new ArgumentException("Specified background color could not be parsed."));
                }

                if (!float.TryParse(strSize, out fSZ))
                {
                    context.AddError(new ArgumentException("Specified font size is not a valid floating point integer value."));
                }

                // Try and parse the font style value into an integer as a check to
                //   see what kind of value was passed.
                if (int.TryParse(strStyle, out iFntStyle))
                {
                    // If the value is an integer, it's probably a bit array of
                    //   enumeration flags.
                    style = (FontStyle)iFntStyle;
                }
                else
                {
                    // If the value is not an integer, try and parse the enumeration
                    //   value directly.
                    style = (string.IsNullOrEmpty(strStyle))
                        ? FontStyle.Regular
                        : (FontStyle)Enum.Parse(typeof(FontStyle), strStyle, true);
                }

                align = (string.IsNullOrEmpty(strAlign))
                        ? System.Web.UI.WebControls.HorizontalAlign.NotSet
                        : (System.Web.UI.WebControls.HorizontalAlign)Enum.Parse(typeof(System.Web.UI.WebControls.HorizontalAlign), strAlign);
            }
            catch (Exception ex)
            {
                exKeep = ex;
            }

            using (Bitmap bmp = new Bitmap(iW, iH))
            {
                using (Graphics g = Graphics.FromImage(bmp))
                {
                    if (exKeep == null)
                    {
                        g.Clear(bgClr);
                        using (StringFormat format = new StringFormat(StringFormatFlags.NoWrap))
                        {
                            if (align == System.Web.UI.WebControls.HorizontalAlign.Center)
                            {
                                format.Alignment = StringAlignment.Center;
                            }
                            else if (align == System.Web.UI.WebControls.HorizontalAlign.Right)
                            {
                                format.Alignment = StringAlignment.Far;
                            }
                            else
                            {
                                format.Alignment = StringAlignment.Near;
                            }
                            format.LineAlignment = StringAlignment.Center;
                            format.Trimming      = StringTrimming.EllipsisCharacter;

                            RectangleF rect = new RectangleF(new PointF(0, 0), new SizeF((float)iW, (float)iH));

                            using (Font font = new Font(strFont, fSZ, style))
                                using (Brush brush = new SolidBrush(fgClr))
                                    g.DrawString(DateTime.Now.ToString(strFormat), font, brush, rect, format);
                        }
                    }
                    else
                    {
                        GraphicsUnit gu = g.PageUnit;
                        g.Clear(Color.White);
                        using (Font font = new Font("Tahoma", 6.0f, FontStyle.Regular))
                            g.DrawString(exKeep.Message, font, Brushes.Black, bmp.GetBounds(ref gu));
                    }
                }
                using (System.IO.MemoryStream fs = new System.IO.MemoryStream())
                {
                    bmp.Save(fs, System.Drawing.Imaging.ImageFormat.Png);
                    byte[] strmData = fs.ToArray();
                    context.Response.OutputStream.Write(strmData, 0, strmData.Length);
                }
            }
        }
        public override void AddAttributesToRender(HtmlTextWriter writer, WebControl owner)
        {
            base.AddAttributesToRender(writer, owner);
            int cellSpacing = this.CellSpacing;

            if (cellSpacing >= 0)
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing, cellSpacing.ToString(NumberFormatInfo.InvariantInfo));
                if (cellSpacing == 0)
                {
                    writer.AddStyleAttribute(HtmlTextWriterStyle.BorderCollapse, "collapse");
                }
            }
            cellSpacing = this.CellPadding;
            if (cellSpacing >= 0)
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding, cellSpacing.ToString(NumberFormatInfo.InvariantInfo));
            }
            System.Web.UI.WebControls.HorizontalAlign horizontalAlign = this.HorizontalAlign;
            if (horizontalAlign != System.Web.UI.WebControls.HorizontalAlign.NotSet)
            {
                string str = "Justify";
                switch (horizontalAlign)
                {
                case System.Web.UI.WebControls.HorizontalAlign.Left:
                    str = "Left";
                    break;

                case System.Web.UI.WebControls.HorizontalAlign.Center:
                    str = "Center";
                    break;

                case System.Web.UI.WebControls.HorizontalAlign.Right:
                    str = "Right";
                    break;

                case System.Web.UI.WebControls.HorizontalAlign.Justify:
                    str = "Justify";
                    break;
                }
                writer.AddAttribute(HtmlTextWriterAttribute.Align, str);
            }
            if (this.GridLines != System.Web.UI.WebControls.GridLines.None)
            {
                string str2 = string.Empty;
                switch (this.GridLines)
                {
                case System.Web.UI.WebControls.GridLines.Horizontal:
                    str2 = "rows";
                    break;

                case System.Web.UI.WebControls.GridLines.Vertical:
                    str2 = "cols";
                    break;

                case System.Web.UI.WebControls.GridLines.Both:
                    str2 = "all";
                    break;
                }
                writer.AddAttribute(HtmlTextWriterAttribute.Rules, str2);
            }
        }