您的位置:首页 > 编程语言 > C#

C#学习笔记(5)

2014-02-28 17:03 549 查看
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace demo5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void trackBar1_Scroll(object sender, EventArgs e)
{
textBox1.Text = trackBar1.Value.ToString();		//显示所调节的button1的宽度
button1.Width = trackBar1.Value;       			//设置button1的宽度
}

private void trackBar2_Scroll(object sender, EventArgs e)
{
textBox2.Text = trackBar2.Value.ToString();
button1.Height = trackBar2.Value;
}

private void button1_Click(object sender, EventArgs e)
{
ButtonParameter BP = new ButtonParameter();   //实例化一个ButtonParameter对象BP
BP.Text = "按钮控件";   					//BP的Text属性设置为“按钮控件”
button1.Text = BP.Text; 						//设置button1的Text属性
button1.Height = BP.Height;					//设置button1的Height属性
button1.Width = BP.Width;  					//设置button1的Width属性

label1.Text = "默认高度为:";
label2.Text = "默认宽度为:";
textBox1.Text = BP.Height.ToString();			//显示默认高度
textBox2.Text = BP.Width.ToString();			//显示默认宽度
}
class ButtonParameter       						//定义类ButtonParameter
{
private string _text;   							//按钮的Text属性值
private int _height;    							//按钮的Height属性值
private int _width;     							//按钮的Width属性值
public ButtonParameter()						//构造函数
{
_height = 23;
_width = 75;
}
public string Text								//Text属性,可读可写
{
get									//读访问器
{ return _text; }
set									//写访问器
{ _text = value; }
}
public int Height   							//只读属性,Height属性
{
get
{ return _height; }
}
public int Width    							//只读属性,Width属性
{
get
{ return _width; }
}
}
}
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: