Ejemplo n.º 1
0
        public FrmdelegateSetUI()
        {
            InitializeComponent();

            richText.AddService(typeof(ISyntaxHighlightService), new SyntaxHighlightService(richText));
            IRichEditCommandFactoryService      commandFactory    = richText.GetService <IRichEditCommandFactoryService>();
            CustomRichEditCommandFactoryService newCommandFactory = new CustomRichEditCommandFactoryService(commandFactory);

            richText.RemoveService(typeof(IRichEditCommandFactoryService));
            richText.AddService(typeof(IRichEditCommandFactoryService), newCommandFactory);

            IDocumentImportManagerService importManager = richText.GetService <IDocumentImportManagerService>();

            importManager.UnregisterAllImporters();
            importManager.RegisterImporter(new PlainTextDocumentImporter());
            importManager.RegisterImporter(new SourcesCodeDocumentImporter());

            IDocumentExportManagerService exportManager = richText.GetService <IDocumentExportManagerService>();

            exportManager.UnregisterAllExporters();
            exportManager.RegisterExporter(new PlainTextDocumentExporter());
            exportManager.RegisterExporter(new SourcesCodeDocumentExporter());

            richText.LoadDocument(@"C:\Users\Public\Documents\DevExpress Demos 14.1\Components\WinForms\CS\RichEditMainDemo\Modules\SyntaxHighlight.cs", DocumentFormat.PlainText);
        }
        public void Initialize(IRichEditControl richEditControl, string codeExamplesFileExtension)
        {
            InnerRichEditControl innerControl = richEditControl.InnerControl;

            IRichEditCommandFactoryService commandFactory = innerControl.GetService <IRichEditCommandFactoryService>();

            if (commandFactory == null)
            {
                return; // wpf richedit is not loaded
            }
            innerControl.ReplaceService <ISyntaxHighlightService>(new SyntaxHighlightService(innerControl, codeExamplesFileExtension));

            CustomRichEditCommandFactoryService newCommandFactory = new CustomRichEditCommandFactoryService(commandFactory);

            innerControl.RemoveService(typeof(IRichEditCommandFactoryService));
            innerControl.AddService(typeof(IRichEditCommandFactoryService), newCommandFactory);

            IDocumentImportManagerService importManager = innerControl.GetService <IDocumentImportManagerService>();

            importManager.UnregisterAllImporters();
            importManager.RegisterImporter(new PlainTextDocumentImporter());
            importManager.RegisterImporter(new SourcesCodeDocumentImporter());

            IDocumentExportManagerService exportManager = innerControl.GetService <IDocumentExportManagerService>();

            exportManager.UnregisterAllExporters();
            exportManager.RegisterExporter(new PlainTextDocumentExporter());
            exportManager.RegisterExporter(new SourcesCodeDocumentExporter());

            Document document = innerControl.Document;

            document.BeginUpdate();
            try
            {
                document.DefaultCharacterProperties.FontName = "Consolas";
                document.DefaultCharacterProperties.FontSize = 10;
                document.Sections[0].Page.Width                = Units.InchesToDocumentsF(100);
                document.Sections[0].LineNumbering.CountBy     = 1;
                document.Sections[0].LineNumbering.RestartType = LineNumberingRestart.Continuous;

                //SizeF tabSize = innerControl.MeasureSingleLineString("    ", document.DefaultCharacterProperties);
                //TabInfoCollection tabs = document.Paragraphs[0].BeginUpdateTabs(true);
                //try {
                //    for (int i = 1; i <= 30; i++) {
                //        DevExpress.XtraRichEdit.API.Native.TabInfo tab = new DevExpress.XtraRichEdit.API.Native.TabInfo();
                //        tab.Position = i * tabSize.Width;
                //        tabs.Add(tab);
                //    }
                //}
                //finally {
                //    document.Paragraphs[0].EndUpdateTabs(tabs);
                //}
            }
            finally
            {
                document.EndUpdate();
            }
        }
        void richEdit_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
            richEdit.Options.AutoCorrect.DetectUrls              = false;
            richEdit.Options.AutoCorrect.ReplaceTextAsYouType    = false;
            richEdit.Options.Behavior.PasteLineBreakSubstitution = LineBreakSubstitute.Paragraph;
            DocumentCapabilitiesOptions caps = richEdit.Options.DocumentCapabilities;

            caps.Bookmarks            = DocumentCapability.Disabled;
            caps.CharacterStyle       = DocumentCapability.Disabled;
            caps.HeadersFooters       = DocumentCapability.Disabled;
            caps.Hyperlinks           = DocumentCapability.Disabled;
            caps.InlinePictures       = DocumentCapability.Disabled;
            caps.Numbering.Bulleted   = DocumentCapability.Disabled;
            caps.Numbering.MultiLevel = DocumentCapability.Disabled;
            caps.Numbering.Simple     = DocumentCapability.Disabled;
            caps.ParagraphFormatting  = DocumentCapability.Disabled;
            caps.ParagraphStyle       = DocumentCapability.Disabled;
            caps.Sections             = DocumentCapability.Disabled;
            caps.Tables          = DocumentCapability.Disabled;
            caps.TableStyle      = DocumentCapability.Disabled;
            caps.FloatingObjects = DocumentCapability.Disabled;
            richEdit.Options.HorizontalRuler.Visibility      = RichEditRulerVisibility.Hidden;
            richEdit.Views.DraftView.AllowDisplayLineNumbers = true;
            richEdit.Views.DraftView.Padding = new Padding(60, 4, 0, 0);

            richEdit.AddService(typeof(ISyntaxHighlightService), new SyntaxHighlightService(richEdit));
            IRichEditCommandFactoryService      commandFactory    = richEdit.GetService <IRichEditCommandFactoryService>();
            CustomRichEditCommandFactoryService newCommandFactory = new CustomRichEditCommandFactoryService(commandFactory);

            richEdit.RemoveService(typeof(IRichEditCommandFactoryService));
            richEdit.AddService(typeof(IRichEditCommandFactoryService), newCommandFactory);

            IDocumentImportManagerService importManager = richEdit.GetService <IDocumentImportManagerService>();

            importManager.UnregisterAllImporters();
            importManager.RegisterImporter(new PlainTextDocumentImporter());
            importManager.RegisterImporter(new SourcesCodeDocumentImporter());

            IDocumentExportManagerService exportManager = richEdit.GetService <IDocumentExportManagerService>();

            exportManager.UnregisterAllExporters();
            exportManager.RegisterExporter(new PlainTextDocumentExporter());
            exportManager.RegisterExporter(new SourcesCodeDocumentExporter());

            string codeModuleName = "SyntaxHighlighting";

            richEdit.Options.DocumentSaveOptions.CurrentFileName = CodeFileLoadHelper.GetCodeFileName(codeModuleName);
            CodeFileLoadHelper.Load(codeModuleName, richEdit);
        }
Ejemplo n.º 4
0
        public void Initialize(IRichEditControl richEditControl, string codeExamplesFileExtension)
        {
            InnerRichEditControl innerControl = richEditControl.InnerControl;

            IRichEditCommandFactoryService commandFactory = innerControl.GetService <IRichEditCommandFactoryService>();

            if (commandFactory == null)
            {
                return;
            }

            innerControl.ReplaceService <ISyntaxHighlightService>(new SyntaxHighlightService(innerControl, codeExamplesFileExtension));

            CustomRichEditCommandFactoryService newCommandFactory = new CustomRichEditCommandFactoryService(commandFactory);

            innerControl.RemoveService(typeof(IRichEditCommandFactoryService));
            innerControl.AddService(typeof(IRichEditCommandFactoryService), newCommandFactory);

            IDocumentImportManagerService importManager = innerControl.GetService <IDocumentImportManagerService>();

            importManager.UnregisterAllImporters();
            importManager.RegisterImporter(new PlainTextDocumentImporter());
            importManager.RegisterImporter(new SourcesCodeDocumentImporter());

            IDocumentExportManagerService exportManager = innerControl.GetService <IDocumentExportManagerService>();

            exportManager.UnregisterAllExporters();
            exportManager.RegisterExporter(new PlainTextDocumentExporter());
            exportManager.RegisterExporter(new SourcesCodeDocumentExporter());

            Document document = innerControl.Document;

            document.BeginUpdate();
            try
            {
                document.DefaultCharacterProperties.FontName = "Consolas";
                document.DefaultCharacterProperties.FontSize = 10;
                document.Sections[0].Page.Width                = Units.InchesToDocumentsF(100);
                document.Sections[0].LineNumbering.CountBy     = 1;
                document.Sections[0].LineNumbering.RestartType = LineNumberingRestart.Continuous;
            }
            finally
            {
                document.EndUpdate();
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.richEditControl = new DevExpress.XtraRichEdit.RichEditControl();
            this.SuspendLayout();

            //
            // richEditControl
            //
            this.richEditControl.ActiveViewType = DevExpress.XtraRichEdit.RichEditViewType.Simple;
            this.richEditControl.Dock           = System.Windows.Forms.DockStyle.Fill;
            this.richEditControl.EnableToolTips = true;
            this.richEditControl.Location       = new System.Drawing.Point(2, 2);
            this.richEditControl.Margin         = new System.Windows.Forms.Padding(5, 5, 5, 5);
            this.richEditControl.Name           = "richEditControl";
            this.richEditControl.Options.AutoCorrect.DetectUrls                    = false;
            this.richEditControl.Options.AutoCorrect.ReplaceTextAsYouType          = false;
            this.richEditControl.Options.Behavior.PasteLineBreakSubstitution       = DevExpress.XtraRichEdit.LineBreakSubstitute.Paragraph;
            this.richEditControl.Options.CopyPaste.MaintainDocumentSectionSettings = false;
            this.richEditControl.Options.DocumentCapabilities.Bookmarks            = DevExpress.XtraRichEdit.DocumentCapability.Disabled;
            this.richEditControl.Options.DocumentCapabilities.CharacterStyle       = DevExpress.XtraRichEdit.DocumentCapability.Disabled;
            this.richEditControl.Options.DocumentCapabilities.HeadersFooters       = DevExpress.XtraRichEdit.DocumentCapability.Disabled;
            this.richEditControl.Options.DocumentCapabilities.Hyperlinks           = DevExpress.XtraRichEdit.DocumentCapability.Disabled;
            this.richEditControl.Options.DocumentCapabilities.InlinePictures       = DevExpress.XtraRichEdit.DocumentCapability.Disabled;
            this.richEditControl.Options.DocumentCapabilities.Numbering.Bulleted   = DevExpress.XtraRichEdit.DocumentCapability.Disabled;
            this.richEditControl.Options.DocumentCapabilities.Numbering.MultiLevel = DevExpress.XtraRichEdit.DocumentCapability.Disabled;
            this.richEditControl.Options.DocumentCapabilities.Numbering.Simple     = DevExpress.XtraRichEdit.DocumentCapability.Disabled;
            this.richEditControl.Options.DocumentCapabilities.ParagraphFormatting  = DevExpress.XtraRichEdit.DocumentCapability.Disabled;
            this.richEditControl.Options.DocumentCapabilities.Paragraphs           = DevExpress.XtraRichEdit.DocumentCapability.Enabled;
            this.richEditControl.Options.DocumentCapabilities.ParagraphStyle       = DevExpress.XtraRichEdit.DocumentCapability.Disabled;
            this.richEditControl.Options.DocumentCapabilities.Sections             = DevExpress.XtraRichEdit.DocumentCapability.Disabled;
            this.richEditControl.Options.DocumentCapabilities.Tables               = DevExpress.XtraRichEdit.DocumentCapability.Disabled;
            this.richEditControl.Options.DocumentCapabilities.TableStyle           = DevExpress.XtraRichEdit.DocumentCapability.Disabled;
            this.richEditControl.Options.Fields.UseCurrentCultureDateTimeFormat    = false;
            this.richEditControl.Options.HorizontalRuler.Visibility                = DevExpress.XtraRichEdit.RichEditRulerVisibility.Hidden;
            this.richEditControl.Options.MailMerge.KeepLastParagraph               = false;
            this.richEditControl.Size     = new System.Drawing.Size(1111, 627);
            this.richEditControl.TabIndex = 1;
            this.richEditControl.Text     = "richEditControl1";
            this.richEditControl.Views.SimpleView.AllowDisplayLineNumbers = true;
            this.richEditControl.Views.SimpleView.Padding = new System.Windows.Forms.Padding(80, 4, 0, 0);
            this.richEditControl.InitializeDocument      += new System.EventHandler(this.richEditControl_InitializeDocument);
            richEditControl.AddService(typeof(ISyntaxHighlightService), new SyntaxHighlightService(richEditControl));
            IRichEditCommandFactoryService      commandFactory    = richEditControl.GetService <IRichEditCommandFactoryService>();
            CustomRichEditCommandFactoryService newCommandFactory = new CustomRichEditCommandFactoryService(commandFactory);

            richEditControl.RemoveService(typeof(IRichEditCommandFactoryService));
            richEditControl.AddService(typeof(IRichEditCommandFactoryService), newCommandFactory);

            IDocumentImportManagerService importManager = richEditControl.GetService <IDocumentImportManagerService>();

            importManager.UnregisterAllImporters();
            importManager.RegisterImporter(new PlainTextDocumentImporter());
            importManager.RegisterImporter(new SourcesCodeDocumentImporter());

            IDocumentExportManagerService exportManager = richEditControl.GetService <IDocumentExportManagerService>();

            exportManager.UnregisterAllExporters();
            exportManager.RegisterExporter(new PlainTextDocumentExporter());
            exportManager.RegisterExporter(new SourcesCodeDocumentExporter());

            richEditControl.LoadDocument(@"C:\Users\Public\Documents\DevExpress Demos 14.1\Components\WinForms\CS\RichEditMainDemo\Modules\SyntaxHighlight.cs", DocumentFormat.PlainText);

            //
            // SyntaxHighlightModule
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 22F);
            this.AutoScaleMode       = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize          = new System.Drawing.Size(1115, 631);
            this.Controls.Add(this.richEditControl);
            this.Margin = new System.Windows.Forms.Padding(5, 5, 5, 5);
            this.Name   = "SyntaxHighlightModule";
            this.ResumeLayout(false);
        }