⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 Visual C#2005程序设计教程
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WinApp6_2方法调用
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            double l = double.Parse(txtLength.Text);
            double w = double.Parse(txtWidth.Text);
            double h = double.Parse(txtHigh.Text);
            Cuboid cuboid = new Cuboid();
            cuboid.Length = l;
            cuboid.Width = w;
            cuboid.High = h;
            lblInfo.Text = cuboid.CuboidShow();   // 求体积的方法在类定义内调用
        }

        private void button2_Click(object sender, EventArgs e)
        {
            double l = double.Parse(txtLength.Text);
            double w = double.Parse(txtWidth.Text);
            double h = double.Parse(txtHigh.Text);
            Cuboid cuboid = new Cuboid();
            cuboid.Length = l;
            cuboid.Width = w;
            cuboid.High = h;
            lblInfo.Text = "长方体的长、宽、高为:" + cuboid.Length + "、"
                + cuboid.Width + "、" + cuboid.High + "\n长方体的体积为:"
                + cuboid.Cubage( );
        }
    }
    class Cuboid
    {
        private double length;
        private double width;
        private double high;
        public double Length { get { return length; } set { length = value; } }
        public double Width { get { return width; } set { width = value; } }
        public double High { get { return high; } set { high = value; } }
        public double Cubage() { return length * width * high; }
        public string CuboidShow()
        {
            return "长方体的长、宽、高为:" + length + " " + width + " " + high
                + "   \n长方体的体积为:" + Cubage();
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -