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;
using System.Drawing.Drawing2D;

namespace wave
{
    public partial class frmMain : Form
    {
       
        public frmMain()
        {
            InitializeComponent();
        }
    

        #region 属 性
     
        //数据采样
        private List listData = new List();


        //随机数
        private Random myRandom = new Random();
        
        //曲线颜色       
        private Pen lineColor = new Pen(Color.FromArgb(0x00, 0xFF, 0x00));
        //private Pen lineColor = new Pen(Color.Green);
        #endregion


        #region 窗 体 事 件
        
        //时间间隔事件
        private void myTimer_Tick(object sender, EventArgs e)

        {

//listData.Count  是用来控制线条走动的时间、长度等

            while (listData.Count > 100) listData.RemoveAt(0);
            listData.Add((byte)myRandom.Next(256));
           
            Invalidate();


        }


       //窗体初始化 先  
        private void frmMain_Load(object sender, EventArgs e)
        {
            DoubleBuffered = true;
            myTimer.Enabled = true;
            myTimer.Interval = 100;
            this.Top = 200;
            this.Left = Screen.PrimaryScreen.Bounds.Width - 110;
            this.Width = 100;
            this.Height = 100;
            GraphicsPath shape = new GraphicsPath();
            shape.AddEllipse(0, 0, 100, 100);
            this.Region = new Region(shape);
        }
 
        // 绘制窗体
        private void frmMain_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.FillRectangle(Brushes.Black, e.Graphics.ClipBounds);


            // 小于一条数据直接返回
            if (listData.Count <= 1) return;
            //绘制曲线
            for (int i = listData.Count - 1; i >= 0; i--)
            {
                byte data = listData[i];
            //直线起点与终点Y轴坐标
                int sy = 10 + (int)((this.Height - 10) * (1 - ((double)data / 256)));
                int ey = this.Height;
            //直线起点与终点坐标
                Point sPoint = new Point(this.Width - listData.Count + i, sy+20);
                Point ePoint = new Point(this.Width - listData.Count + i, ey);
            //绘制直线
                e.Graphics.DrawLine(lineColor, sPoint, ePoint);
               #region 添加时钟    
                lblTime.Text = System.DateTime.Now.ToString("HH:mm:ss");
                #endregion
            }
        }
        
              #region 双击事件
        private void frmMain_DoubleClick(object sender, EventArgs e)
        {
           
        }
        #endregion
        #endregion


        #region    鼠标移动
        private Point ptMouseCurrrnetPos, ptMouseNewPos, ptFormPos, ptFormNewPos;
        private bool blnMouseDown = false;
        private void frmMain_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                blnMouseDown = true;
                ptMouseCurrrnetPos = Control.MousePosition;
                ptFormPos = Location;
            }
        }




        private void frmMain_MouseMove(object sender, MouseEventArgs e)
        {
            if (blnMouseDown)
            {
                //Get the current position of the mouse in the screen
                ptMouseNewPos = Control.MousePosition;
                //Set window position
                ptFormNewPos.X = ptMouseNewPos.X - ptMouseCurrrnetPos.X + ptFormPos.X;
                ptFormNewPos.Y = ptMouseNewPos.Y - ptMouseCurrrnetPos.Y + ptFormPos.Y;
                //Save window position
                Location = ptFormNewPos;
                ptFormPos = ptFormNewPos;
                //Save mouse position
                ptMouseCurrrnetPos = ptMouseNewPos;
            }
        }


        private void frmMain_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
                //Return back signal
                blnMouseDown = false;
        }
        #endregion
    }
}

你可能感兴趣的:(c#实现动态悬浮窗代码(可用于检测))