有3个常用方法

1.MouseMove事件中,使选不中

private void textBox3_MouseMove(object sender, MouseEventArgs e)
{
if (this.textBox3.SelectionLength > 0)
{
this.textBox3.SelectionStart = this.textBox1.TextLength;
this.textBox3.SelectionLength = 0;
}
}

2.

新建一个类,取名为TextBox.cs,代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace frmLogin
{
    public class TextBoxEx : System.Windows.Forms.TextBox
    {
        //
        //构造函数默认的
        //

protected override void WndProc(ref   Message m)
        {
            if (m.Msg != 0x007B && m.Msg != 0x0301 && m.Msg != 0x0302)
            {
                base.WndProc(ref m);
            }
        }


}

0x007B:鼠标右键 message ID

0x0301:复制 (包括ctrl+c) message ID (其实这个判断不要,因为设置textbox的PasswordChar属性 实际上已经屏蔽了复制功能)

0x0302:粘贴(包括ctrl+v) message ID

更多的message ID 可以参考http://liuhao-27.blog.163.com/blog/static/115851126200941425617778/

或查阅API手册

当然,在这里的我们的工作还没有结束,我们需要在Login.Designer.cs中将txtPassword引用这个新的对象,

this.txtPassword = new System.Windows.Forms.TextBox();

改为:

this.txtPassword = new frmLogin.TextBoxEx();

3.textBox.ShortcutsEnabled 设置为false

winform文本框不能粘贴、复制和屏蔽右键的更多相关文章

  1. Winform文本框只能输入限定的文本

    比如WInform中的文本框只能输入数字活着字母和退格键,e.kaychar(按下键盘的值)

  2. WinForm 文本框验证

    这是一个自定义控件,继承了TextBox,在TextBox基础上添加了4个属性(下载): 1.ControlType 文本框需要验证的类型 2.ControlTypeText 显示的文字(只读) 3. ...

  3. c# winform文本框数字,数值校验

    文本框数字,数值校验 public void DigitCheck_KeyPress(object sender, KeyPressEventArgs e) { e.Handled = !char.I ...

  4. 多个文本框点击复制 zClip (ZeroClipboard)有关问题

    <script type="text/javascript" src="js/jquery.min.js"$amp;>amp;$lt;/script ...

  5. C# Winform 文本框默认提示信息

    private string Notes = "提示文本"; private void textBox1_Leave(object sender, EventArgs e) { / ...

  6. Winform 文本框多线程赋值

    delegate void SetTextCallback(string text); private void showClientMsg(string text) { // InvokeRequi ...

  7. .net(c#) winform文本框只能输入数字,不能其他非法字符

    private void textBox3_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { //阻止从键盘输入键 ...

  8. 关于winform文本框怎么实现html的placeholder效果

    winfrom默认是不支持这种操作的,此时需要重写控件操作,具体代码如下: public class TextBoxEx : TextBox { public String PlaceHolderSt ...

  9. C#,WinForm文本框录入内容判断

    || e.KeyChar > ) && (e.KeyChar != ) && (e.KeyChar != ) && (e.KeyChar != ) ...

随机推荐

  1. cygwin完全安装步骤方法(组图)

    我们可以到Cygwin的官方网站下载Cygwin的安装程序,地址是: http://www.cygwin.com/ 或者直接使用下载连接来下载安装程序,下载连接是: http://www.cygwin ...

  2. A. Dreamoon and Stairs(Codeforces Round #272)

    A. Dreamoon and Stairs time limit per test 1 second memory limit per test 256 megabytes input standa ...

  3. HDUOJ----专题训练

    Problem B Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) Total Su ...

  4. 【LeetCode】130. Surrounded Regions (2 solutions)

    Surrounded Regions Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'. A ...

  5. sqoop安装遇到的问题

    错误: 找不到或无法加载主类 org.apache.sqoop.Sqoop最终解决办法是吧sqoop目录下的sqoop-1.4.4.jar拷贝到hadoop的lib目录下解决 Warning: /us ...

  6. 最全Android开发常用工具类

    主要介绍总结的Android开发中常用的工具类,大部分同样适用于Java. 目前包括  HttpUtils.DownloadManagerPro.Safe.ijiami.ShellUtils.Pack ...

  7. 重写 View 的 Touch 方法,实现一个酷炫的九宫格图片

    前几天翻看代码库,发现一个之前写过的一个有意思的小玩意,共享给大家

  8. [MFC]图形附加alpha透明通道

    改动图形而且附加透明通道: 要附加透明度,能够要把图片转化为32位png图片,然后设置对应的alpha值: 1.      怎样把一张图片改动为32位的Png: a)        读取原图片颜色信息 ...

  9. Jvisualvm监控远程linux下Tomcat

    Jvisualvm监控远程linux下Tomcat 1.编辑tomcat/bin/catalina.sh 加入下面这段代码,中间无换行: CATALINA_OPTS="$CATALINA_O ...

  10. mysql - 语法复习与学习

    //本月的第一天,最后一天 $start=date('Y-m-01', strtotime(date("Y-m-d"))); echo date('Y-m-d', strtotim ...