Implementing Select All Functionality


Just to demonstrate how easy it is to go back and modify this code once it has been created, you are going to implement the Select All method that you added to your menu.

To do this, start by editing the ICutCopyPaste interface to include the following method signature:

 Sub SelectAll() 

Then add the code in Listing 6-13 to the frmEditBase class.

Listing 6-13: The SelectAll Method

start example
 Public Sub SelectAll() Implements ICutCopyPaste.SelectAll      Dim txt As TextBoxBase      If TypeOf ActiveControl Is TextBoxBase Then           txt = CType(ActiveControl, TextBoxBase)           txt.SelectAll()      End If End Sub 
end example

This code calls the SelectAll method on the TextBoxBase control, which takes care of the work for you. Now you need to update your main form to invoke this method. Edit the Select Case statement in the MainMenu_Click method in the frmMain class so that it looks like the following:

 Case "Cu&t", "&Copy", "&Paste", "Select Al&l"      CutCopyPaste(mnu.Text) 

Next, edit the CutCopyPaste routine by adding the following Case statement to the Select Case block:

 Case "Select Al&l"      objCCPU.SelectAll() 

Now you should be able to click the Select All menu item to select all of the text in a textbox or richtextbox on any edit form. Of course you only have the one right now, but it works for everything.




Building Client/Server Applications with VB. NET(c) An Example-Driven Approach
Building Client/Server Applications Under VB .NET: An Example-Driven Approach
ISBN: 1590590708
EAN: 2147483647
Year: 2005
Pages: 148
Authors: Jeff Levinson

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net