e媒网络

一切皆可能 e媒网络 http://www.eMay.net

博客园 首页 新随笔 联系 订阅 管理

代码参考:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WindowsCircleArea.Lib
{
    public class Circle
    {
        private int radius;
        public Circle(int r)
        {
            radius = r;
        }
        public double GetArea()
        {
            return Math.PI * radius * radius;
        }
        public double Area
        {
            get
            {
                return Math.PI * radius * radius;
            }
        }
    }
}

参考代码2:

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;
using WindowsCircleArea.Lib;

namespace WindowsCircleArea
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnArea_Click(object sender, EventArgs e)
        {
            int iOutR = int.Parse(txtOutR.Text);
            int iInR1 = int.Parse(txtInR1.Text);
            int iInR2 = int.Parse(txtInR2.Text);
            Circle outCircle = new Circle(iOutR);
            Circle inCircle1 = new Circle(iInR1);
            Circle inCircle2 = new Circle(iInR2);
            double area = outCircle.Area-inCircle1.Area -inCircle2.Area;
            lblArea.Text = "蓝色水域的面积是:"+area.ToString();
            pB.Image = Properties.Resources.c1;
        }      

        private void Form1_Load(object sender, EventArgs e)
        {
            pB.Image = Properties.Resources.c1;
        }

        private void txtOutR_Enter(object sender, EventArgs e)
        {
            pB.Image = Properties.Resources.c2;
        }

        private void txtInR1_Enter(object sender, EventArgs e)
        {
            pB.Image = Properties.Resources.c3;
        }

        private void txtInR2_Enter(object sender, EventArgs e)
        {
            pB.Image = Properties.Resources.c4;
        }
     
    }
}

 

posted on 2022-12-19 09:29  e媒网络技术团队  阅读(19)  评论(0编辑  收藏  举报