c# DevExpress 中富文本richeditcontrol 关于字体和页面布局内容的设置

c# DevExpress 中富文本richeditcontrol 关于字体和页面布局内容的设置

//文档默认格式设置
        private void doc_default(Document doc)
        {
     
            DocumentRange range1 = richEditControl1.Document.Range;
            CharacterProperties cp = this.richEditControl1.Document.BeginUpdateCharacters(range1);
            cp.FontName = "宋体";//打开文件默认文字字体
            cp.FontSize = 14; //打开文件默认文字大小
            doc.Sections[0].Page.PaperKind = System.Drawing.Printing.PaperKind.A4;//设置纸张大小           
            doc.Sections[0].Margins.Left = 180f;//设置左边距
            doc.Sections[0].Margins.Right = 180f;//设置右边距
            DocumentPosition pos = doc.Selection.Start;
            DocumentRange range = doc.CreateRange(pos, 0);
            ParagraphProperties pp = doc.BeginUpdateParagraphs(range);
            pp.LineSpacingType = ParagraphLineSpacing.Sesquialteral;//设置段落1.5倍行距                              
            doc.EndUpdateParagraphs(pp);
            doc.EndUpdateCharacters(cp);

            //页眉设置
            // 第一页 页眉设置
            Section firstSection = doc.Sections[0];
            SubDocument myHeader = firstSection.BeginUpdateHeader(HeaderFooterType.First);
            get_docheader(doc, myHeader, firstSection);
            //document.AppendSection(); //添加一页
            //除第一页 之外的页眉设置
            int pagecount = this.richEditControl1.Document.Sections.Count;
            for (int p = 0; p <= pagecount - 1; p++)
            {
     
                Section elseSection = doc.Sections[p];
                SubDocument myotherHeader = firstSection.BeginUpdateHeader(HeaderFooterType.Odd);
                get_docheader(doc, myotherHeader, elseSection);
            }

        }
//第一页标题设置
        private void set_title(Document document)
        {
     
            DocumentRange range2 = document.Paragraphs[0].Range;
            CharacterProperties cp2 = document.BeginUpdateCharacters(range2);
            ParagraphProperties pp2 = document.BeginUpdateParagraphs(range2);
            ParagraphProperties pp3 = document.BeginUpdateParagraphs(document.Paragraphs[1].Range);
            pp2.Alignment = ParagraphAlignment.Center;//标题居中
            pp3.Alignment = ParagraphAlignment.Center;
            cp2.FontName = "宋体";
            cp2.FontSize = 20;
            //cp2.Strikeout = StrikeoutType.Single;//设置中间线条
            //cp2.Underline = UnderlineType.Single;//设置下划线
            document.EndUpdateParagraphs(pp2);
            document.EndUpdateParagraphs(pp3);
            document.EndUpdateCharacters(cp2);
        }
//文档页眉内容和字体的设置
        private void get_docheader(Document document, SubDocument myHeader, Section firstSection)
        {
     
            DocumentRange range3 = myHeader.InsertText(myHeader.CreatePosition(0), "第");
            Field fld = myHeader.Fields.Create(range3.End, "PAGE");//当前页数
            myHeader.AppendText("页 共");
            Field fld2 = myHeader.Fields.Create(range3.End, "NUMPAGES");//总页数
            myHeader.AppendText("页");

            ParagraphProperties gg = myHeader.BeginUpdateParagraphs(range3);
            gg.Alignment = ParagraphAlignment.Right;//页眉内容居右
            document.EndUpdateParagraphs(gg);
            CharacterProperties cp3 = myHeader.BeginUpdateCharacters(range3);
            cp3.FontName = "宋体";
            cp3.FontSize = 10;
            document.EndUpdateCharacters(cp3);
            myHeader.Fields.Update();
            firstSection.EndUpdateHeader(myHeader);
            firstSection.DifferentFirstPage = true;

        }

你可能感兴趣的:(C#,C#)