简易密码输入自定义控件示例 含自定义事件 可在调用窗口事件视图中看到事件名
来源:互联网 发布:百度云管家for mac 编辑:程序博客网 时间:2024/05/17 03:44
public partial class MyCheckBox : UserControl
{
string text=string.Empty;
bool bAutoSrcoll=true;
Size sSize;
public MyCheckBox()
{
InitializeComponent();
textBox1.TextChanged +=new EventHandler(Right_Click);
}
[Description("文本框内输入的内容")]
public string MyText
{
get { return text; }
set
{
textBox1.Text = value;
text = value;
}
}
[Description("光标跟随编辑位置")]
public bool AutoSrcoll
{
get { return bAutoSrcoll; }
set
{
bAutoSrcoll = value;
}
}
// [Description("文本更改")]
public delegate void RTextChangedEventHandler(object sender, RTextChangedEventArgs e);//事件所需的委托
//当颜色改变时触发事件
public event RTextChangedEventHandler RTextChanged;//定义一个ColorChanged事件
protected virtual void OnTextChanged(RTextChangedEventArgs e)
{//事件触发方法
if (RTextChanged != null)
{//判断事件是否为空
RTextChanged(this, e);//触发事件
}
}
public class RTextChangedEventArgs : EventArgs
{
public string str;
public RTextChangedEventArgs()
{
str = "right";
}
}
private void Right_Click(object sender, EventArgs e)
{
RTextChanged(this, new RTextChangedEventArgs());
}
private void SetSign(int Position)
{
string temp = string.Empty;
for (int i = 0; i < textBox1.Text.Length; i++)
{
temp += @"*";
}
textBox1.Text = temp;
if (bAutoSrcoll == true)
{
textBox1.Select(Position + 1, 0);
}
else
{
textBox1.Select(textBox1.Text.Length, 0);
}
textBox1.ScrollToCaret();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (MyText.Length == textBox1.Text.Length) //显示回显
{
string tmp = textBox1.Text.Replace(@"*", "");
if (tmp.Trim().Length != 0)
{
SetSign(textBox1.Text.Length);
}
return;
}
//输入空,不需回显
if (string.IsNullOrEmpty(textBox1.Text) == true)
{
text = string.Empty;
return;
}
string input = textBox1.Text.Replace(@"*", "");
if (input == string.Empty)//输入*号,不需回显
{
text = text + @"*";
return;
}
else
{
int inputset = textBox1.Text.LastIndexOf(input);
if (inputset == text.Length)//追加
{
text += input;
}
else//插入
text = text.Insert(inputset, input);
SetSign(inputset);
}
}
}
- 简易密码输入自定义控件示例 含自定义事件 可在调用窗口事件视图中看到事件名
- 控件:UIControl 我在UITextFiled输入事件调用到
- Swift实现自定义AlertView,灵活添加自定义视图到AlertView,可响应事件
- 自定义事件监听器示例
- Qt自定义窗口事件
- 用户控件自定义事件
- 控件的自定义事件
- 自定义控件的事件
- 自定义控件添加事件
- C#-控件-自定义事件
- 自定义控件加事件
- 自定义控件添加事件
- 自定义控件添加事件
- 自定义控件添加事件
- Winform自定义控件事件
- .net 自定义控件事件
- 自定义控件触动事件
- C# 自定义控件,自定义属性,自定义事件
- from表单序列化&JQuery源代码中两个小扣好的意义&StringUtils的用法
- mount error 12 = Cannot allocate memory
- 设计模式-单例
- Object C self and super 关键字
- struts2 jsp File "/struts-tags" not found
- 简易密码输入自定义控件示例 含自定义事件 可在调用窗口事件视图中看到事件名
- 详细的SQL事务
- FFmpeg和h.264是什么关系
- struts2和jquery_validator简单使用
- hdu 1698 Just a Hook
- serializer
- 图论;单源最短路径;拓扑排序+松弛(有向无回路);Bellman-Ford(回路,负权回路);Dijkstra(无负权,可回路);可以用最小堆实现算法的优化;
- How ASP.NET MVC Works(重点)
- linux系统目录介绍