天天看點

小練習(c#):畫很多圓

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#):畫很多圓