C#学习笔记(5)

简介: 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 Syst
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; }
            }
        }
    }
}

目录
相关文章
|
C#
C#中的数组型参数学习笔记
C#中的数组型参数学习笔记
295 1
halcon联合c#、WPF学习笔记三(dispatcherTimer实时相机显示)
halcon联合c#、WPF学习笔记三(dispatcherTimer实时相机显示)
1258 2
halcon联合c#、WPF学习笔记三(dispatcherTimer实时相机显示)
|
C# C++
halcon联合c#、WPF学习笔记一(WPF配置halcon)
halcon联合c#、WPF学习笔记一(WPF配置halcon)
2361 1
|
测试技术 持续交付 C#
C#程序基础开发入门学习笔记
C#是一种现代的、面向对象的编程语言,广泛应用于Windows应用程序开发、游戏开发(尤其是Unity引擎)、Web应用程序以及跨平台应用等。
557 0
halcon联合c#、WPF学习笔记二(简单案例)
halcon联合c#、WPF学习笔记二(简单案例)
2114 0
|
C# C语言
C#学习笔记22: 面向对象编程入门精讲(下)
C#学习笔记22: 面向对象编程入门精讲
C#学习笔记22: 面向对象编程入门精讲(下)
c#编程:事件delegate学习笔记-3
c#编程:事件delegate学习笔记-3
316 0
|
缓存 开发框架 运维
C#好代码学习笔记(1):文件操作、 读取文件、Debug/Trace类、Conditional条件编译、CLS
C#好代码学习笔记(1):文件操作、 读取文件、Debug/Trace类、Conditional条件编译、CLS
470 0
|
开发框架 并行计算 .NET
改善C#程序的157个建议——建议84学习笔记:使用PLINQ
改善C#程序的157个建议——建议84学习笔记:使用PLINQ
311 0