在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例Windows系统编程 → winform仿qq停靠屏幕边缘

winform仿qq停靠屏幕边缘

Windows系统编程

下载此实例
  • 开发语言:C#
  • 实例大小:0.23M
  • 下载次数:40
  • 浏览次数:507
  • 发布时间:2020-01-13
  • 实例类别:Windows系统编程
  • 发 布 人:MrCyl
  • 文件格式:.zip
  • 所需积分:3
 相关标签: 屏幕 QQ

实例介绍

【实例简介】

    winform仿qq停靠屏幕边缘

【实例截图】

from clipboard

from clipboard

【核心代码】

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        #region  公共变量
        IntPtr Tem_Handle;//获取控件及窗体的句柄
        Point CPoint;//获取控件中鼠标的坐标
        static int Tem_place = 0;
        int Frm_Height = 0;
        int FrmHeight = 0;

        #endregion

        #region  API声明
        //获取当前鼠标下可视化控件的句柄
        [DllImport("user32.dll")]
        public static extern int WindowFromPoint(int xPoint, int yPoint);
        //获取指定句柄的父级句柄
        [DllImport("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto)]
        public static extern IntPtr GetParent(IntPtr hWnd);
        //获取屏幕的大小
        [DllImport("user32.dll", EntryPoint = "GetSystemMetrics")]
        private static extern int GetSystemMetrics(int mVal);
        #endregion

        #region  获取当前鼠标下可视化控件的句柄
        /// <summary>
        /// 获取当前鼠标下可视化控件的句柄
        /// </summary>
        /// <param x="int">当前鼠标的X坐标</param>
        /// <param y="int">当前鼠标的Y坐标</param>
        public IntPtr FormNameAt(int x, int y)
        {
            IntPtr Tem_hWnd;//设置存储句柄的变量
            Tem_Handle = (IntPtr)(WindowFromPoint(x, y));//获取当前鼠标下可视化控件的句柄
            Tem_hWnd = Tem_Handle;//记录原始句柄
            while (Tem_hWnd != ((IntPtr)0))//遍历该句柄的父级句柄
            {
                Tem_Handle = Tem_hWnd;//记录当前句柄
                Tem_hWnd = GetParent(Tem_hWnd);//获取父级句柄
            }
            return Tem_Handle;//返回最底层的父级句柄
        }
        #endregion


        private void timer1_Tick(object sender, EventArgs e)
        {
            if (this.Top < 3 && Tem_place==0)//如果窗体被移到屏幕的顶部
                {
                    if (this.Handle == FormNameAt(Cursor.Position.X, Cursor.Position.Y))//当鼠标移致到该窗体上
                    {
                        panel_Title.Tag = 1;//设置标识,用于判断窗体在屏幕顶部
                        timer2.Enabled = false;//不对窗体进行拉伸操作
                        this.Top = 0;//使窗体致顶
                    }
                    else
                    {
                        panel_Title.Tag = 1;//设置标识,用于判断窗体在屏幕顶部
                        timer2.Enabled = true;//将窗体在顶部进行隐藏
                    }
                }
                else
                {
                    if (this.Left < 3 || this.Right > GetSystemMetrics(0) - 3)//如果窗体被移到屏幕的左端或右端
                    {
                        if (this.Left < 3)//如果窗体被移到屏幕的左端
                        {
                            if (this.Handle == FormNameAt(Cursor.Position.X, Cursor.Position.Y))//当鼠标移致到该窗体上
                            {
                                panel_Title.Tag = 2;//设置标识,用于判断窗体在屏幕左端
                                timer2.Enabled = false;
                                Frm_Height = this.Height;
                                this.Left = 0;//使窗体致左
                                this.Top = 0;
                                this.Height = Screen.AllScreens[0].Bounds.Height;
                                Tem_place = 1;
                            }
                            else
                            {
                                panel_Title.Tag = 2;
                                timer2.Enabled = true;//将窗体在左端进行隐藏
                            }
                        }
                        if (this.Right > GetSystemMetrics(0) - 3)//如果窗体被移到屏幕的右端
                        {
                            if (this.Handle == FormNameAt(Cursor.Position.X, Cursor.Position.Y))//当鼠标移致到该窗体上
                            {
                                panel_Title.Tag = 3;//设置标识,用于判断窗体在屏幕右端
                                timer2.Enabled = false;
                                Frm_Height = this.Height;
                                this.Left = GetSystemMetrics(0) - this.Width;//使窗体致右
                                this.Top = 0;
                                this.Height = Screen.AllScreens[0].Bounds.Height;
                                Tem_place = 1;
                            }
                            else
                            {
                                panel_Title.Tag = 3;
                                timer2.Enabled = true;//将窗体在右端进行隐藏
                            }
                        }

                    }
                }

        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            switch (Convert.ToInt16(panel_Title.Tag.ToString()))//对标识进行判断
            {
                case 1://顶端隐藏
                    {
                        if (this.Top < 5)
                            this.Top = -(this.Height - 2);
                        break;
                    }
                case 2://左端隐藏
                    {
                        if (this.Left < 5)
                            this.Left = -(this.Width - 2);
                        break;
                    }
                case 3://右端隐藏
                    {
                        if ((this.Left this.Width) > (GetSystemMetrics(0) - 5))
                            this.Left = GetSystemMetrics(0) - 2;
                        break;
                    }
            }
        }

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

        #region  利用窗体上的控件移动窗体
        /// <summary>
        /// 利用控件移动窗体
        /// </summary>
        /// <param Frm="Form">窗体</param>
        /// <param e="MouseEventArgs">控件的移动事件</param>
        public void FrmMove(Form Frm, MouseEventArgs e)  //Form或MouseEventArgs添加命名空间using System.Windows.Forms;
        {
            if (e.Button == MouseButtons.Left)
            {
                Point myPosittion = Control.MousePosition;//获取当前鼠标的屏幕坐标
                myPosittion.Offset(CPoint.X, CPoint.Y);//重载当前鼠标的位置
                Frm.DesktopLocation = myPosittion;//设置当前窗体在屏幕上的位置
                Tem_place = 0;
                this.Height = FrmHeight;
            }
        }
        #endregion

        private void panel_Title_MouseDown(object sender, MouseEventArgs e)
        {
            timer1.Enabled = false;
            CPoint = new Point(-e.X, -e.Y);
        }

        private void panel_Title_MouseMove(object sender, MouseEventArgs e)
        {
            FrmMove(this, e);
        }

        private void panel_Title_MouseUp(object sender, MouseEventArgs e)
        {
            timer1.Enabled = true;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Frm_Height = this.Height;
            FrmHeight = this.Height;
            this.TopMost = true;
        }
    }

标签: 屏幕 QQ

实例下载地址

winform仿qq停靠屏幕边缘

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警