Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old October 29th, 2005, 08:00 PM
Registered User
Join Date: Aug 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to wslyhbb Send a message via MSN to wslyhbb Send a message via Yahoo to wslyhbb
Default Deleting text from a RichTextBox

The RichTextBox does not provide a Delete function like it does for Cut(), Copy(), and Paste(). From what I have found on the Internet to delete text you set the SelectedText equal to an empty string. While this works, the UndoActionName of the RichTextBox is "Unknown", why?
My question is, is setting SelectedText equal to an empty string really the correct way of deleting text in a RichTextBox and if so, how can I set the UndoActionName to "Delete"?

My code:
            // get selected text in the text box
            string selectedText = richTextBox.SelectedText;

            if (selectedText.Length > 0)
                richTextBox.SelectedText = "";
            // otherwise, if not the end of the document, remove the first character after the caret
                int caretPosition = richTextBox.SelectionStart;
                if (caretPosition != richTextBox.TextLength)
                    richTextBox.Select(caretPosition, 1);
                    richTextBox.SelectedText = "";

Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating, Writing to and Deleting Text Files goels Access VBA 7 January 30th, 2007 11:51 AM
Deleting text strings automatically from Database palvin SQL Server 2000 15 October 3rd, 2005 12:52 PM
Editing text in a richtextbox ja8261 VB.NET 2002/2003 Basics 5 March 9th, 2005 04:10 PM
help changing text, and deleting elements... phoenix2005 XSLT 13 December 23rd, 2004 09:12 AM
#region text in RichTextBox? mfourre C# 1 August 7th, 2003 12:49 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.