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


C# FastColoredTextBox.InsertText方法代码示例

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


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

示例1: DropFromTheInside

        private static void DropFromTheInside(FastColoredTextBox textbox, Place place, string text)
        {
            Range insertRange = new Range(textbox, place, place);

            // Determine, if the dragged string should be copied or moved
            bool copyMode =
                (textbox.draggedRange == null) ||       // drag from outside
                (textbox.draggedRange.ReadOnly) ||      // dragged range is read only
                ((Control.ModifierKeys & Keys.Control) != Keys.None);

            if (!textbox.draggedRange.Contains(place))
            {
                textbox.BeginAutoUndo();
                textbox.Selection.BeginUpdate();

                //remember dragged selection for undo/redo
                textbox.Selection = textbox.draggedRange;
                textbox.lines.Manager.ExecuteCommand(new SelectCommand(textbox.lines));
                //

                if (textbox.draggedRange.ColumnSelectionMode)
                {
                    // dropping a block selection, add a few new lines
                    textbox.draggedRange.Normalize();
                    var endLine = place.iLine + textbox.draggedRange.End.iLine - textbox.draggedRange.Start.iLine;
                    var end = new Place(place.iChar,endLine );
                    insertRange = new Range(textbox, place, end) { ColumnSelectionMode = true };
                    for (int i = textbox.LinesCount; i <= insertRange.End.iLine; i++)
                    {
                        textbox.Selection.GoLast(false);
                        textbox.InsertChar('\n');
                    }
                }

                if (!insertRange.ReadOnly)
                {
                    if (place < textbox.draggedRange.Start)
                    {
                        // Target place is before the dragged range,
                        // first delete dragged range if not in copy mode
                        if (copyMode == false)
                        {
                            textbox.Selection = textbox.draggedRange;
                            textbox.ClearSelected(); // clear original selectin
                        }

                        // Insert text
                        textbox.Selection = insertRange;
                        textbox.Selection.ColumnSelectionMode = insertRange.ColumnSelectionMode;
                        textbox.InsertText(text);
                    }
                    else
                    {
                        // Target place is after the dragged range, first insert the text
                        // Insert text
                        textbox.Selection = insertRange;
                        textbox.Selection.ColumnSelectionMode = insertRange.ColumnSelectionMode;
                        textbox.InsertText(text);

                        // Delete dragged range if not in copy mode
                        if (copyMode == false)
                        {
                            textbox.Selection = textbox.draggedRange;
                            textbox.ClearSelected();
                        }
                    }
                }

                // Selection start and end position
                Place startPosition = place;
                Place endPosition = textbox.Selection.Start;

                // Correct selection
                Range dR = (textbox.draggedRange.End > textbox.draggedRange.Start)  // dragged selection
                    ? RangeUtil.GetRange(textbox, textbox.draggedRange.Start, textbox.draggedRange.End)
                    : RangeUtil.GetRange(textbox, textbox.draggedRange.End, textbox.draggedRange.Start);
                Place tP = place; // targetPlace
                int tS_S_Line;  // targetSelection.Start.iLine
                int tS_S_Char;  // targetSelection.Start.iChar
                int tS_E_Line;  // targetSelection.End.iLine
                int tS_E_Char;  // targetSelection.End.iChar
                if ((place > textbox.draggedRange.Start) && (copyMode == false))
                {
                    if (textbox.draggedRange.ColumnSelectionMode == false)
                    {
                        // Normal selection mode:

                        // Determine character/column position of target selection
                        if (dR.Start.iLine != dR.End.iLine) // If more then one line was selected/dragged ...
                        {
                            tS_S_Char = (dR.End.iLine != tP.iLine)
                                ? tP.iChar
                                : dR.Start.iChar + (tP.iChar - dR.End.iChar);
                            tS_E_Char = dR.End.iChar;
                        }
                        else // only one line was selected/dragged
                        {
                            if (dR.End.iLine == tP.iLine)
                            {
                                tS_S_Char = tP.iChar - dR.Text.Length;
//.........这里部分代码省略.........
开发者ID:rickaas,项目名称:FastColoredTextBox,代码行数:101,代码来源:DoDragDropHelper.cs

示例2: DropFromTheOutside

 private static void DropFromTheOutside(FastColoredTextBox textbox, Place place, string text)
 {
     textbox.Selection.BeginUpdate();
     // Insert text
     textbox.Selection.Start = place;
     textbox.InsertText(text);
     // Select inserted text
     textbox.Selection = new Range(textbox, place, textbox.Selection.Start);
     textbox.Selection.EndUpdate();
 }
开发者ID:rickaas,项目名称:FastColoredTextBox,代码行数:10,代码来源:DoDragDropHelper.cs

示例3: OpenTab


//.........这里部分代码省略.........
                             else
                                 iswait = true;
                         } catch {
                             MessageBox.Show( this, "Fix code editor at preferences window \r\nPath: File->Preferences->Scripts and codes" );
                             return;
                         }
                         if ( RB1.Text != txt )
                             return;
                         RB1.VisibleRange.ClearStyles( false );
                         RB1.VisibleRange.ClearFoldingMarkers( false );
                         List<Token> lt = tokenizer.Tokenize( RB1.VisibleRange.Text );
                         Lexer.Lexing( ref lt );
                         PaintTextBox( RB1, lt );
                     } catch {
                         MessageBox.Show(this, "Exception caught while painting" );
                     }
                 } ) ).Start( );
             } ) );
         } ) ).Start( );
     } );
     RB1.KeyDown += new KeyEventHandler( ( object sender, KeyEventArgs kea ) => {
         RB1.SelectionStyle.BackgroundBrush = new SolidBrush( preferencesWindow.colors[ 4 ] );
         RB1.Font = preferencesWindow.f;
         //runningForm.savedProject = false;
         int speccount = 0;
         bool isstr = false;
         int ind = RB1.Selection.Start.iChar;
         List<Char> txt = RB1[ RB1.Selection.Start.iLine ];
         txt.ForEach( new Action<Char>( ( Char c ) => {
             if ( --ind <= -1 )
                 return;
             if ( c.c == '"' || c.c == '\'' )
                 isstr = isstr == false;
         } ) );
         if ( isstr )
             return;
         string astr = RB1.Text.Substring( 0, RB1.SelectionStart );
         int startline = astr.LastIndexOf( '\n', RB1.SelectionStart - 1 );
         if ( startline == -1 )
             startline = 0;
         string astr2 = astr.Substring( startline );
         if ( kea.KeyValue == 219 && kea.Shift ) {
             kea.Handled = true;
             RB1.InsertText( " {\r\n" + new string( ' ', RB1[ RB1.Selection.Start.iLine ].StartSpacesCount + RB1.TabLength ) );
             iswait = false;
             RB1.OnTextChanged( );
         } else if ( kea.KeyValue == 8 && RB1.SelectionStart > 0 && RB1.SelectionLength == 0 ) {
             astr = RB1.Text;
             startline = astr.LastIndexOf( '\n', RB1.SelectionStart - 1 ) + 1;
             if ( astr.Substring( startline, RB1.SelectionStart - startline ) == new string( ' ', RB1.SelectionStart - startline ) ) {
                 speccount = RB1.SelectionStart - startline;
                 if ( startline != 0 )
                     speccount += 2;
                 RB1.SelectionStart -= speccount;
                 RB1.SelectionLength = speccount;
                 RB1.SelectedText = "";
                 kea.Handled = true;
             }
         } else if ( kea.KeyValue == 13 ) {
             int spaces = RB1[ RB1.Selection.Start.iLine ].StartSpacesCount;
             if ( RB1.Selection.CharAfterStart == '\n' )
                 return;
             RB1.InsertText( "\r\n" + new string( ' ', spaces ) );
             kea.Handled = true;
         } else if ( kea.KeyValue == 221 && kea.Shift ) {
             kea.Handled = true;
             int spaces = RB1[ RB1.Selection.Start.iLine ].StartSpacesCount;
             if ( astr2.Replace( " ", "" ) == "\n" ) {
                 if ( astr2.Length > RB1.TabLength + 1 ) {
                     RB1.SelectionStart -= RB1.TabLength;
                     RB1.SelectionLength = RB1.TabLength;
                     RB1.SelectedText = "}\r\n" + new string( ' ', spaces - RB1.TabLength );
                 } else {
                     RB1.SelectionStart = startline + 1;
                     RB1.SelectionLength = astr2.Length - 1;
                     RB1.SelectedText = "}\r\n";
                 }
             } else {
                 if ( spaces < RB1.TabLength + 1 ) {
                     RB1.InsertText( "\r\n}\r\n" + new string( ' ', spaces ) );
                 } else {
                     RB1.InsertText( "\r\n" + new string( ' ', spaces - RB1.TabLength ) + "}\r\n" + new string( ' ', spaces - RB1.TabLength ) );
                 }
             }
         }
     } );
     RB1.Text = File.ReadAllText( path );
     RB1.Height = RB1.Width = 2500;
     faTabStripItem.Controls.Add( RB1 );
     faTabStripItem.Tag = path;
     _TabControl1.Items.Add( faTabStripItem );
     List<Token> lt2 = tokenizer.Tokenize( RB1.Text );
     Lexer.Lexing( ref lt2 );
     PaintTextBox( RB1, lt2 );
     RB1.OnTextChanged( );
     RB1.ClearLineChanges( );
     faTabStripItem.Saved = true;
     OpenTab( path );
     _TabControl1.Invalidate( );
 }
开发者ID:VarocalCross,项目名称:Varocal,代码行数:101,代码来源:Form1.cs

示例4: Split

 private void Split(int iLine, FastColoredTextBox tb, string s)
 {
     string[] sep = s.Split(':');
     tb.Selection.Start = new Place(0, iLine);
     tb.Selection.Expand();
     string seperator;
     if (sep.Length == 3 && sep[1] == string.Empty)
         seperator = ":";
     else
         seperator = sep[1];
     var lines = tb.SelectedText.Split(seperator.ToCharArray());
     tb.ClearSelected();
     foreach (string line in lines)
     {
         tb.InsertText(line+"\n");
     }
     tb.ClearCurrentLine();
 }
开发者ID:samarjeet27,项目名称:ynoteclassic,代码行数:18,代码来源:MainForm.cs

示例5: Paste

        /// <summary>
        /// Paste text from clipboard into selected position
        /// </summary>
        public static void Paste(FastColoredTextBox textbox)
        {
            string text = null;
            var thread = new Thread(() =>
            {
                if (Clipboard.ContainsText())
                    text = Clipboard.GetText();
            });
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            thread.Join();

            // get result from event handler, because pasting could be cancelled.
            TextChangingEventArgs result = textbox.OnPasting(text);

            if (result.Cancel)
            {
                text = string.Empty;
            }
            else
            {
                text = result.InsertingText;
            }

            if (!string.IsNullOrEmpty(text))
            {
                textbox.InsertText(text);
            }
        }
开发者ID:rickaas,项目名称:FastColoredTextBox,代码行数:32,代码来源:EditorCommands.cs

示例6: DuplicateLine

 public void DuplicateLine(int iLine, FastColoredTextBox fctb)
 {
     fctb.Selection.Start = new Place(0, iLine);
     fctb.Selection.Expand();
     object text = fctb.Selection.Text;
     fctb.Selection.Start = new Place(0, iLine);
     fctb.InsertText(text + "\r\n" + "\r\n");
 }
开发者ID:phaufe,项目名称:ynoteclassic,代码行数:8,代码来源:Main.cs


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