home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples.exe / Wintalk / CS / DataEdit.cs < prev    next >
Encoding:
Text File  |  2000-06-23  |  1.8 KB  |  68 lines

  1. /*+==========================================================================
  2.   File:      DataEdit.cs
  3.  
  4.   Summary:   Extends the default functionality of the WFC Edit control
  5.              by providing two extra methods.
  6.  
  7.   Classes:   DataEdit
  8.  
  9.   Functions: Append, TruncateOneCharFromEnd
  10.              
  11. ----------------------------------------------------------------------------
  12.   This file is part of the Microsoft NGWS Samples.
  13.  
  14.   Copyright (C) 1998-2000 Microsoft Corporation.  All rights reserved.
  15. ==========================================================================+*/
  16.  
  17. using System;
  18. using System.WinForms;
  19. using System.WinForms.Design;
  20.  
  21. public class DataEdit : TextBox
  22. {
  23. /*****************************************************************************
  24.  Function :    Append
  25.  
  26.  Abstract:     Appends a string to the end of the edit control
  27.             
  28.  Input Parameters: str(String)
  29.  
  30.  Returns: void
  31. ******************************************************************************/
  32.     public void Append(String str)
  33.     {
  34.         int len = Text.Length;
  35.         SelectionStart = len;
  36.         SelectionLength = len;
  37.         SelectedText = str;
  38.     }
  39.  
  40. /*****************************************************************************
  41.  Function:     TruncateOneCharFromEnd
  42.  
  43.  Abstract:     Truncates one character from the end of the text in the edit
  44.                control.
  45.             
  46.  Input Parameters: (none)
  47.  
  48.  Returns: void
  49. ******************************************************************************/
  50.     public void TruncateOneCharFromEnd()
  51.     {
  52.         int len = Text.Length;
  53.         if (len == 1) {
  54.             Text = "";
  55.         } else if (len > 1) {
  56.             SelectionStart = len-1;
  57.             SelectionLength = len;
  58.             String s = SelectedText;
  59.             if (s.Equals("\n")) {
  60.                 SelectionStart = len-2;
  61.                 SelectionLength = len;
  62.             }
  63.             SelectedText = "";
  64.         }
  65.     }
  66.         
  67. }
  68.