马上加入IBC程序猿 各种源码随意下,各种教程随便看! 注册 每日签到 加入编程讨论群

C#教程 ASP.NET教程 C#视频教程程序源码享受不尽 C#技术求助 ASP.NET技术求助

【源码下载】 社群合作 申请版主 程序开发 【远程协助】 每天乐一乐 每日签到 【承接外包项目】 面试-葵花宝典下载

官方一群:

官方二群:

窗口停靠缩进代码

[复制链接]
查看10055 | 回复5 | 2013-9-21 13:00:11 | 显示全部楼层 |阅读模式
实现像QQ一样,将窗口停靠所缩进,代码共享,

[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.Threading;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            //this.StartPosition = FormStartPosition.Manual;
            //this.Location = new Point(0, 0);

        }
      
        private void Form1_Load(object sender, EventArgs e)
        {
                 this.TopMost = true;
 
            this.timer1.Start();
            //int a  = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
            //int b = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;
            //MessageBox.Show(a,b);
        }
        internal AnchorStyles StopAanhor = AnchorStyles.None;
        private void mStopAnhor()
 
        {
 
            if (this.Top <= 0 && this.Left <= 0)
 
            {
 
                StopAanhor = AnchorStyles.None;
 
            }
 
            else if (this.Top <= 0)
 
            {
 
                StopAanhor = AnchorStyles.Top;
 
            }
 
            //else if (this.Left <= 0)
 
            //{
 
            //    StopAanhor = AnchorStyles.Left;
 
            //}
 
            else if (this.Left >= Screen.PrimaryScreen.Bounds.Width - this.Width)
 
            {
 
                StopAanhor = AnchorStyles.Right;
 
            }
 
            else if (this.Top >= Screen.PrimaryScreen.Bounds.Height - this.Height)
 
            {
 
                StopAanhor = AnchorStyles.Bottom;
 
            }
 
            else
 
            {
 
                StopAanhor = AnchorStyles.None;
 
            }
 
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
              if (this.Bounds.Contains(Cursor.Position))
 
     {
 
          switch (this.StopAanhor)
 
          {
 
               case AnchorStyles.Top:
 
                   this.Location = new Point(this.Location.X, 0);
 
                   break;
 
               case AnchorStyles.Left:
 
                   this.Location = new Point(0, this.Location.Y);
 
                   break;
 
               case AnchorStyles.Right:
 
                   this.Location = new Point(Screen.PrimaryScreen.Bounds.Width - this.Width, this.Location.Y);
 
                    break;
 
               case AnchorStyles.Bottom:
 
                    this.Location = new Point(this.Location.X, Screen.PrimaryScreen.Bounds.Height - this.Height);
 
                    break;
 
            }
 
       }
 
       else
 
       {
 
            switch (this.StopAanhor)
 
            {
 
                 case AnchorStyles.Top:
 
                     this.Location = new Point(this.Location.X, (this.Height - 4) * (-1));
 
                     break;
 
                 case AnchorStyles.Left:
 
                    this.Location = new Point((-1) * (this.Width - 4), this.Location.Y);
 
                    break;
 
                 case AnchorStyles.Right:
 
                    this.Location = new Point(Screen.PrimaryScreen.Bounds.Width - 4, this.Location.Y);
 
                    break;
 
                 case AnchorStyles.Bottom:
 
                    this.Location = new Point(this.Location.X, (Screen.PrimaryScreen.Bounds.Height - 4));
 
                    break;
 
                }
 
            }
 
        }

        private void Form1_LocationChanged(object sender, EventArgs e)
        {
               this.mStopAnhor();
        }

        
        
       
      

    }
}




C#论坛 www.ibcibc.com IBC编程社区
C#
C#论坛
IBC编程社区
2013-9-27 13:21:35
你好老师情况怎么样[tthread=Nurali2675, Nurali][/tthread]
2013-9-27 13:21:36
什么? || @Nurali2675: 你好老师情况怎么样[tthread=c4wangluo, 原道楠]http://app.qlogo.cn/mbloghead/ebef5598fbc9a840d456[/tthread]
ibcadmin | 2013-10-8 15:37:54 | 显示全部楼层
啊啊啊
C#论坛 www.ibcibc.com IBC编程社区
C#
C#论坛
IBC编程社区
2768549658 | 2013-10-8 17:22:32 | 显示全部楼层
asdads
心镜先生 | 2013-12-2 11:16:09 | 显示全部楼层
赞赞赞赞
*滑块验证:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则