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 放大镜
{
    public partial class Form1 : Form
    {
        Bitmap backImage;
        Point MouseLocation;
        public Form1()
        {
            InitializeComponent();
            backImage = new Bitmap(pictureBox1.Width / 2, pictureBox1.Height / 2);
           

        }
        int loc;
        bool fangDa = false;
        private void button1_Click(object sender, EventArgs e)
        {
            if (fangDa == false)
            {
                fangDa = true;
                timer1.Start();
            }
            else
            {
                fangDa = false;
                timer1.Stop();
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (fangDa == true)
            {
                MouseLocation = new Point(Cursor.Position.X, Cursor.Position.Y);
                FangDa();
            }
            else
                return;
        }
        private void FangDa()
        {
            if (backImage != null)
            {
                Graphics g = Graphics.FromImage(backImage);
                g.CopyFromScreen(new Point(MouseLocation.X - 24, MouseLocation.Y - 24), new Point(0, 0), backImage.Size);
                this.pictureBox1.Image = backImage;
                g.Dispose();
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex != -1)
            {
                int beiShu = comboBox1.SelectedIndex;
                switch (beiShu)
                {
                    case 0:
                        backImage = new Bitmap(100, 100);
                        break;
                    case 1:
                        backImage = new Bitmap(50, 50);
                        break;
                    case 2:
                        backImage = new Bitmap(25, 25);
                        break;
                    default:
                        backImage = new Bitmap(100, 100);
                        break;
                }
            }
        }


    }
}
//用到一个Size(100,100)PictureBox的控件

//timer控件

//按钮 控件

//combox控件

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页