VS2005 winform用户控件(三):给控件添加新的属性
来源:互联网 发布:斗鱼潮人老杨淘宝 编辑:程序博客网 时间:2024/05/21 07:03
本例中,在(二)的基础上,给用户控件添加一个新的属性。用于返回一个字符串。
全部代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace WindowsControlLibrary1
{
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
private string newTextValue;//定义一个私有属性
public string _newTextValue
{
get { return newTextValue; }
set { newTextValue = value; }
}
private void UserControl1_Load(object sender, EventArgs e)
{
this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox1_KeyPress);
this.textBox1.TextChanged += new System.EventHandler(this.UserControl1_TabIndexChanged);
}
private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
int ch = e.KeyChar;
if (((ch >= 48) && (ch <= 57) || ch == 8 || ch == 13) == false)
{
e.Handled = true;
}
}
private void UserControl1_TabIndexChanged(object sender, EventArgs e)
{
this.newTextValue ="你输入的值是:"+this.textBox1.Text;
}
}
}
调用程序的全部代码 :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
this.Text = this.userControl11._newTextValue;
}
}
}
欢迎访问我的blog
http://blog.csdn.net/xjzdr/
- VS2005 winform用户控件(三):给控件添加新的属性
- Unity3D 给NGUI自带的控件添加新属性
- 给用户自定义控件添加属性
- 给控件添加属性
- VS2005 winform用户控件(一):入门篇
- 给Qt的控件添加新信号
- asp.net给用户控件添加事件和属性
- 给用户控件设置属性
- 给用户控件添加事件
- 给用户控件添加事件
- VS2005 winform用户控件(二):只能输入数字的textbox控件
- C# 如何给Winform的button等控件添加快捷键
- C# 如何给Winform的button等控件添加快捷键
- C# 如何给Winform的button等控件添加快捷键
- 如何给Winform 的Panel控件添加滚动条
- C# 如何给Winform的button等控件添加快捷键
- C# 如何给Winform的button等控件添加快捷键
- 为用户控件添加属性
- @import 和 link 的区别
- 浅谈sql输出及变量输入及传递
- 存储XML格式数据的原理
- HashMyFiles v1.25
- 微软成功收购雅虎后WPF和Silverlight必将进军YAHOO互联网产品!
- VS2005 winform用户控件(三):给控件添加新的属性
- 08.2.5读书笔记
- FCKeditor 2.2 + Asp.Net 设置 (转帖)
- 搞笑的老公和老婆通信(经典)
- 低端交换机的选购
- 二层交换机,三层交换机,四层交换机的区别
- 台2950交换机相连时不采用TRUNK不同VLAN是否可以通信
- NeoKwinto v2008.01.18
- Happy new year