当前位置: 首页>>代码示例>>C#>>正文


C# RichTextBox.GetParaFormat方法代码示例

本文整理汇总了C#中System.Windows.Forms.RichTextBox.GetParaFormat方法的典型用法代码示例。如果您正苦于以下问题:C# RichTextBox.GetParaFormat方法的具体用法?C# RichTextBox.GetParaFormat怎么用?C# RichTextBox.GetParaFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Forms.RichTextBox的用法示例。


在下文中一共展示了RichTextBox.GetParaFormat方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessTags

        private static string ProcessTags(RichTextBox rtb, List<KeyValuePair<int, string>> colFormat, bool bParaFormat)
        {
            StringBuilder sbT = new StringBuilder();

            ctformatStates bold = ctformatStates.nctNone;
            ctformatStates bitalic = ctformatStates.nctNone;
            ctformatStates bstrikeout = ctformatStates.nctNone;
            ctformatStates bunderline = ctformatStates.nctNone;
            ctformatStates super = ctformatStates.nctNone;
            ctformatStates sub = ctformatStates.nctNone;

            ctformatStates bacenter = ctformatStates.nctNone;
            ctformatStates baleft = ctformatStates.nctNone;
            ctformatStates baright = ctformatStates.nctNone;
            ctformatStates bnumbering = ctformatStates.nctNone;
            bool fontSet = false;
            string strFont = "";
            Int32 crFont = 0;
            Color color = new Color();
            int yHeight = 0;

            int i = 0;
            int pos = 0;
            int k = rtb.TextLength;
            char[] chtrim = { ' ', '\x0000' };

            //--------------------------------
            // this is an inefficient method to get text format
            // but RichTextBox doesn't provide another method to
            // get something like an array of charformat and paraformat
            //--------------------------------
            for (i = 0; i < k; i++)
            {
                // select one character
                rtb.Select(i, 1);
                string strChar = rtb.SelectedText;

                // get format for this character
                CHARFORMAT cf = rtb.GetCharFormat();
                PARAFORMAT pf = rtb.GetParaFormat();

                string strfname = cf.szFaceName;
                strfname = strfname.Trim(chtrim);

                // new font format ?
                if ((strFont != strfname) || (crFont != cf.crTextColor) || (yHeight != cf.yHeight))
                {
                    KeyValuePair<int, string> mfr;
                    if (strFont != "")
                    {
                        // close previous <font> tag
                        mfr = new KeyValuePair<int, string>(pos, "</font>");
                        colFormat.Add(mfr);
                    }

                    // save this for cache
                    strFont = strfname;
                    crFont = cf.crTextColor;
                    yHeight = cf.yHeight;

                    fontSet = strFont != "";

                    // font size should be translate to 
                    // html size (Approximately)
                    int fsize = yHeight / (20 * 5);

                    // color object from COLORREF
                    color = GetColor(crFont);

                    // add <font> tag
                    string strcolor = string.Concat("#", (color.ToArgb() & 0x00FFFFFF).ToString("X6"));

                    mfr = new KeyValuePair<int, string>(pos, "<font face=\"" + strFont + "\" color=\"" + strcolor + "\" size=\"" + fsize + "\">");
                    colFormat.Add(mfr);
                }

                // are we in another line ?
                if ((strChar == "\r") || (strChar == "\n"))
                {
                    // yes?
                    // then, we need to reset paragraph format
                    // and character format
                    if (bParaFormat)
                    {
                        bnumbering = ctformatStates.nctNone;
                        baleft = ctformatStates.nctNone;
                        baright = ctformatStates.nctNone;
                        bacenter = ctformatStates.nctNone;
                    }

                    // close previous tags

                    // is italic? => close it
                    if (bitalic != ctformatStates.nctNone)
                    {
                        var mfr = new KeyValuePair<int, string>(pos, "</i>");
                        colFormat.Add(mfr);
                        bitalic = ctformatStates.nctNone;
                    }

//.........这里部分代码省略.........
开发者ID:Carbenium,项目名称:gitextensions,代码行数:101,代码来源:RichTextBoxXhtmlSupportExtension.cs


注:本文中的System.Windows.Forms.RichTextBox.GetParaFormat方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。