欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

小练习(c#):画很多圆

程序员文章站 2022-05-21 09:30:31
...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1_003Cs语言基础
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Random random = new Random();
        Color getRandomColor()
        {
            return Color.FromArgb(
                random.Next(256),
                random.Next(256),
                random.Next(256)
                );
        }

        private void btnHy_Click(object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics();
            int x = this.Width / 2;
            int y = this.Height / 2;

            for (int r = 1; r <= 100; r++)
            {
                g.DrawEllipse(
                    new Pen(getRandomColor(),2),
                    x-r,y-r,2*r,2*r
                );
            }
            g.Dispose();
        
        }
    }
}

小练习(c#):画很多圆
小练习(c#):画很多圆

相关标签: C# 画圆