程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> C#.NEt-GDI+中的Pen測試

C#.NEt-GDI+中的Pen測試

編輯:C#入門知識

C#.NEt-GDI+中的Pen測試


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;

//1366*768
namespace PaintTest1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            System.Random r = new System.Random();
            Graphics g;
            g = this.CreateGraphics();
  /*         while(true)
           {
               int x1 = r.Next(0, 1366);
               int y1 = r.Next(0, 200);
               int x2 = x1;
               int y2 = y1 + r.Next(0, 400);
               for(int i=y1;i<=y2;i++)
               {
                   Pen greenPen = new Pen(Color.Green, r.Next(1, 15));
                   g.DrawLine(greenPen, x1, y1, x2, y2);
               }
           } */
            for (int i = 0; i < 5000; i++)
            {
                    Pen whitePen = new Pen(Color.FromArgb(r.Next(0,255), r.Next(0,255), r.Next(0,255)),8);
                   int x1 = r.Next(100,300);
                   int y1 = r.Next(100, 500);
                   int x2 = r.Next(100, 300);
                   int y2 = r.Next(100, 500);
                   // int x1 = 500;
                   // int y1 = 500;
                   // int x2 = i;
                   // int y2 = 1000 * 1000 - i * i;
                    g.DrawLine(whitePen, x1, y1, x2, y2);
         
            }
            for (int i = 0; i < 5000; i++)
            {
                Pen whitePen = new Pen(Color.FromArgb(r.Next(0, 255), r.Next(0, 255), r.Next(0, 255)),9);
                int x1 = 500; //650-900
                int y1 = 300; //100-500
                int x2 = r.Next(400, 600);
                int y2 = r.Next(100, 500);
                // int x1 = 500;
                // int y1 = 500;
                // int x2 = i;
                // int y2 = 1000 * 1000 - i * i;
                g.DrawLine(whitePen, x1, y1, x2, y2);

            }
            for (int i = 0; i < 5000; i++)
            {
                Pen whitePen = new Pen(Color.FromArgb(r.Next(0, 255), r.Next(0, 255), r.Next(0, 255)),10);
                int x1 = 900; //650-900
                int y1 = 100; //100-500
                int x2 = r.Next(700, 900);
                int y2 = r.Next(100, 500);
                // int x1 = 500;
                // int y1 = 500;
                // int x2 = i;
                // int y2 = 1000 * 1000 - i * i;
                g.DrawLine(whitePen, x1, y1, x2, y2);

            }
            for (int i = 0; i < 5000; i++)
            {
                Pen whitePen = new Pen(Color.FromArgb(r.Next(0, 255), r.Next(0, 255), r.Next(0, 255)),11);
                int x1 = 1000; //650-900
                int y1 = 500; //100-500
                int x2 = r.Next(1000, 1200);
                int y2 = r.Next(100, 500);
                // int x1 = 500;
                // int y1 = 500;
                // int x2 = i;
                // int y2 = 1000 * 1000 - i * i;
                g.DrawLine(whitePen, x1, y1, x2, y2);

            }
            for (int i = 0; i < 5000; i++)
            {
                Pen whitePen = new Pen(Color.FromArgb(r.Next(0, 255), r.Next(0, 255), r.Next(0, 255)),12);
                int x1 = r.Next(100,1200); ; //650-900
                int y1 = r.Next(600, 700); ; //100-500
                int x2 = r.Next(100, 1200);
                int y2 = r.Next(600, 700);
                // int x1 = 500;
                // int y1 = 500;
                // int x2 = i;
                // int y2 = 1000 * 1000 - i * i;
                g.DrawLine(whitePen, x1, y1, x2, y2);

            }
            for (int i = 0; i < 5000; i++)
            {
                Pen whitePen = new Pen(Color.FromArgb(r.Next(0, 255), r.Next(0, 255), r.Next(0, 255)),r.Next(1,15));
                int x1 = r.Next(100, 1200); ; //650-900
                int y1 = r.Next(600, 700); ; //100-500
                int x2 = r.Next(100, 1200);
                int y2 = r.Next(600, 700);
                // int x1 = 500;
                // int y1 = 500;
                // int x2 = i;
                // int y2 = 1000 * 1000 - i * i;
                g.DrawLine(whitePen, x1, y1, x2, y2);

            }  
        }
    }
}



效果圖<這是一種動態的繪圖,效果還行,下面將改為數字雨的模式測試,相關算法正在調試.

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved