在WEB程序中:
1.用C#控制textBox中的全角和半角,当输入的时候自动变成半角.
2.用C#控制控制textBox中禁止复制和粘贴.请给代码实现.

解决方案 »

  1.   

    第一个问题,参考TextBox的IME控制部分.
    第二个问题,似乎属性里面也有相关控制项.
      

  2.   

    以下内容转自别处>>>>>>>>>>>>重写TextBox以禁止复制粘贴public class TextBoxEx:System.Windows.Forms.TextBox
    {
    private const int WM_GETTEXT=0x000d;
    private const int WM_COPY=0x0301;
    private const int WM_PASTE=0x0302;
    private const int WM_CONTEXTMENU =0x007B;
    private const int WM_RBUTTONDOWN =0x0204;
    public TextBoxEx()
    {
    //
    // TODO: 在此处添加构造函数逻辑
    //
    }
    protected override void WndProc(ref Message m)
    {
    if(m.Msg==WM_RBUTTONDOWN||m.Msg==WM_GETTEXT||m.Msg==WM_COPY)
    return;//WM_RBUTTONDOWN是为了不让出现鼠标菜单
    base.WndProc (ref m);
    }
    }
      

  3.   

    在WEB程序中:
    1.用C#控制textBox中的全角和半角,当输入的时候自动变成半角.
    2.用C#控制控制textBox中禁止复制和粘贴.请给代码实现.
    =====================================================
    1、在Web程序中不同于Windows应用程序,控制不了客户端,除非是流氓软件或者是病毒,所以这个功能实现起来很困难(可能就实现不了)。
    2、第二个功能可以用js来实现。
      

  4.   

    当然在Windows应用程序中,上面的问题都不是问题了。
      

  5.   

    [DllImport("Imm32.dll")]
            public static extern IntPtr ImmGetContext(IntPtr hWnd);        [DllImport("User32.dll")]
            public static extern IntPtr GetKeyboardLayout(int idThread);        [DllImport("Imm32.dll")]
            public static extern int ImmGetConversionList(
                IntPtr hKL,
                IntPtr hIMC,
                string lpSrc,
                IntPtr lpDst,
                int dwBufLen,
                int uFlag              
                );        [DllImport("Imm32.dll")]
            public static extern bool ImmReleaseContext(IntPtr hWnd,IntPtr hIMC);        [StructLayout(LayoutKind.Sequential)]
                public class CANDIDATELIST 
            {
                public int  dwSize;       
                public int  dwStyle;      
                public int  dwCount;      
                public int  dwSelection;  
                public int  dwPageStart;  
                public int  dwPageSize;   
                public int  dwOffset;  
            }        public string[] GetReverseConversion(string AText)
            {
                IntPtr hIMC = ImmGetContext(this.Handle);
                IntPtr hKL = GetKeyboardLayout(0);
                CANDIDATELIST list = new CANDIDATELIST();
                int dwSize = ImmGetConversionList(hKL,hIMC,AText,IntPtr.Zero,0,GCL_REVERSECONVERSION);
                IntPtr BufList = Marshal.AllocHGlobal(dwSize);
                ImmGetConversionList(hKL,hIMC,AText,BufList,dwSize,GCL_REVERSECONVERSION);
                Marshal.PtrToStructure(BufList,list);
                byte[] buf = new byte[dwSize];
                Marshal.Copy(BufList,buf,0,dwSize);
                Marshal.FreeHGlobal(BufList);
                int os = list.dwOffset;
                string str = System.Text.Encoding.Default.GetString(buf,os,buf.Length-os-3);
                char[] par = "\0".ToCharArray();
                string[] strList = str.Split(par);
                ImmReleaseContext(this.Handle,hIMC);
                return strList;
            }
      

  6.   

    private void richTextBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
            {
                if(e.Control&&e.KeyCode==Keys.V)
                {
                    IDataObject iData = Clipboard.GetDataObject();
                    if (iData.GetDataPresent(DataFormats.Text))
                    {
                        //Clipboard.SetDataObject((string) iData.GetData(DataFormats.Text),true);
                        Clipboard.SetDataObject("");
                    }                
                }
            }
      

  7.   

    我的是Web项目啊  大家不要用windows的来解决好么!!!!!!!!!!!!!