FrmScreenTest.cs 5.6 KB
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 TSA_V.Common;

namespace TSA_V
{
    public partial class FrmScreenTest : Form
    {
        public FrmScreenTest()
        {
            InitializeComponent();
        }
        public int ScreenIndex = 1;
     
        private void FrmScreenTest_Load(object sender, EventArgs e)
        {
            this.Text = "显示测试_" + ScreenIndex;
            Screen[] sc = Screen.AllScreens;

            this.StartPosition = FormStartPosition.Manual;
            if (sc.Count() > ScreenIndex)
            {
                Screen screen = sc[ScreenIndex];
                this.Location = new Point(screen.Bounds.Left, screen.Bounds.Top);
                this.WindowState = FormWindowState.Normal;
                this.WindowState = FormWindowState.Maximized;

                string text ="名称:"+ screen.DeviceName+"\r\n";
             //   text += "X:" + screen.Bounds.X + "\r\n";
             //   text += "Y:" + screen.Bounds.Y+ "\r\n";
                text += "Width:" + screen.Bounds.Width+ "\r\n";
                text += "Heigh:" + screen.Bounds.Height+ "\r\n";
                text += "是否主显示器:"+screen.Primary.ToString() + "\r\n"; 
                lblInfo.Text = text;

                SWidth = screen.Bounds.Width;
                SHeight = screen.Bounds.Height;
              
            }
            comboBox1.SelectedIndex = 0;
            btnColor.Text = "颜色:" + CurrColor.Name + "";
            btnColor.BackColor = CurrColor;
        }
        private int SWidth = 0;
        private int SHeight = 0;
        private void FrmScreenTest_Shown(object sender, EventArgs e)
        {
            
        }

        private int index = 0;
        private bool isInProcess = false;
      
        private void button1_Click(object sender, EventArgs e)
        {
            if (isInProcess)
            {
                return;
            }
            isInProcess = true;
            btnDraw.Enabled = false;
            int jianju = FormUtil.GetIntValue(txtJianJu);
            int size = FormUtil.GetIntValue(txtSize);

            int xCount = SWidth / (jianju + size);
            int yCount = SHeight / (jianju + size);
            Graphics g = panel1.CreateGraphics();
            System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Lime);//画刷

            int x = index % 20 * jianju;
            int y = index / 20 * jianju;

             g.FillEllipse(myBrush, new Rectangle(x, y, size, size));//画实心椭圆          
            //  g.FillEllipse(myBrush, new Rectangle(x, y, size, size));//画实心椭圆          
             
            //Font myFont = new Font("宋体", size, FontStyle.Bold);
            //Brush bush = new SolidBrush(Color.Red);//填充的颜色
            //g.DrawString("测试", myFont, bush, x, y);

            g.Dispose();

            index++;
            isInProcess = false;
            btnDraw.Enabled = true;
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            index = 0;
            Graphics g = this.panel1.CreateGraphics();
            g.Clear(Color.Black); 
            g.Dispose();//释放资源
           // this.TransparencyKey = this.panel1.BackColor;
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            if (isInProcess)
            {
                return;
            }
            isInProcess = true;
            btnDraw.Enabled = false;
            btnClear_Click(null, null);
            int jianju = FormUtil.GetIntValue(txtJianJu);
            int size = FormUtil.GetIntValue(txtSize);
            int type = comboBox1.SelectedIndex;
            int xCount = SWidth / (jianju + size)+1;
            int yCount = SHeight / (jianju + size)+1;
            Graphics g = panel1.CreateGraphics();
            int allCount = xCount * yCount;
            System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(CurrColor);//画刷
            Pen pen = new Pen(CurrColor, 1);
            for (int i = 0; i < allCount; i++)
            {
                int x = i % xCount * (jianju+size);
                int y =( i / xCount) * (jianju + size);
                if (type.Equals(0))
                {
                    g.FillEllipse(myBrush, new Rectangle(x, y, size, size));//画实心椭圆          
                }else if (type.Equals(1))
                {
                   g.DrawRectangle(pen, x, y, size, size);
                }
                else if (type.Equals(2))
                {
                    g.DrawEllipse(pen, x, y, size, size);
                }else if (type.Equals(3))
                {
                    g.DrawLine(pen, new Point(x - size, y), new Point(x + size, y));
                    g.DrawLine(pen, new Point(x, y - size), new Point(x, y + size));
                }
            }
          
            g.Dispose();

            index++;
            isInProcess = false;
            btnDraw.Enabled = true;
        }
        private Color CurrColor = Color.White;
        private void btnColor_Click(object sender, EventArgs e)
        {
            colorDialog1.Color = CurrColor;
            colorDialog1.ShowDialog();
            CurrColor = colorDialog1.Color;
            btnColor.Text = "颜色:" + CurrColor.Name + "";
            btnColor.BackColor = CurrColor;
        }
    }
}