FastColoredTextBoxNS.TextStyle.GetCSS C# (CSharp) Method

GetCSS() public method

public GetCSS ( ) : string
return string
        public override string GetCSS()
        {
            string result = "";

            if (BackgroundBrush is SolidBrush)
            {
                var s = ExportToHTML.GetColorAsString((BackgroundBrush as SolidBrush).Color);
                if (s != "")
                    result += "background-color:" + s + ";";
            }
            if (ForeBrush is SolidBrush)
            {
                var s = ExportToHTML.GetColorAsString((ForeBrush as SolidBrush).Color);
                if (s != "")
                    result += "color:" + s + ";";
            }
            if ((FontStyle & FontStyle.Bold) != 0)
                result += "font-weight:bold;";
            if ((FontStyle & FontStyle.Italic) != 0)
                result += "font-style:oblique;";
            if ((FontStyle & FontStyle.Strikeout) != 0)
                result += "text-decoration:line-through;";
            if ((FontStyle & FontStyle.Underline) != 0)
                result += "text-decoration:underline;";

            return result;
        }

Usage Example

示例#1
0
        private string GetCss(StyleIndex styleIndex)
        {
            List <Style> styles = new List <Style>();
            //find text renderer
            TextStyle textStyle    = null;
            int       mask         = 1;
            bool      hasTextStyle = false;

            for (int i = 0; i < tb.Styles.Length; i++)
            {
                if (tb.Styles[i] != null && ((int)styleIndex & mask) != 0)
                {
                    if (tb.Styles[i].IsExportable)
                    {
                        var style = tb.Styles[i];
                        styles.Add(style);

                        bool isTextStyle = style is TextStyle;
                        if (isTextStyle)
                        {
                            if (!hasTextStyle || tb.AllowSeveralTextStyleDrawing)
                            {
                                hasTextStyle = true;
                                textStyle    = style as TextStyle;
                            }
                        }
                    }
                }

                mask = mask << 1;
            }

            //add TextStyle css
            string result = "";

            if (!hasTextStyle)
            {
                //draw by default renderer
                result = tb.DefaultStyle.GetCSS();
            }
            else
            {
                result = textStyle.GetCSS();
            }

            //add no TextStyle css
            foreach (var style in styles)
            {
//            if (style != textStyle)
                if (!(style is TextStyle))
                {
                    result += style.GetCSS();
                }
            }

            return(result);
        }
All Usage Examples Of FastColoredTextBoxNS.TextStyle::GetCSS