【分享】 疯狂的 Form
前两天看到这个帖子 http://topic.csdn.net/t/20050901/16/4244899.html,回去整了下 发现Form 挺有意思的,今天把有意思的代码分享,有点类似 磁性窗体
疯狂的Form主类
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Text;
using System.Drawing;
namespace FormMoving
{
public class MagneticForm : Form
{
private int leftX;
private int rightX;
private int topY;
private int bottomY;
private int HorizonLength ; //计算发生重叠的水平长度
private int VerticalLength ;//计算发生重叠的垂直长度
private bool moveSelf;
/// <summary>
/// 存放互动窗体
/// </summary>
public List<MagneticForm> FormList = new List<MagneticForm>();
/// <summary>
/// 用于设置其他窗体的Location
/// </summary>
private Point tmp = new Point();
/// <summary>
/// 设置或获取Form左边x坐标
/// </summary>
public int LeftX
{
get { return this.leftX; }
set { this.leftX = value; }
}
/// <summary>
/// 设置或获取Form右边x坐标
/// </summary>
public int RightX
{
get { return this.rightX; }
set { this.rightX = value; }
}
/// <summary>
/// 设置或获取Form上边y坐标
/// </summary>
public int TopY
{
get { return this.topY; }
set { this.topY = value; }
}
/// <summary>
/// 设置或获取Form下边y坐标
/// </summary>
public int BottomY
{
get { return this.bottomY; }
set { this.bottomY = value; }
}
public bool MoveSelf
{
get { return this.moveSelf; }
set { this.moveSelf = value; }
}
/// <summary>
///设置联动窗体列表
/// </summary>
/// <param name="form">MagneticForm 类型的窗体</param>
public void SetForms(MagneticForm form)
{
///是自己则不添加
if (!this.Equals(form))
{
this.FormList.Add(form);
}
}
/// <summary>
/// 设置窗体MagneticForm数组相互关联
/// </summary>
/// <param name="forms"></param>
public void SetFormsArray(MagneticForm[] forms)
{
foreach (MagneticForm f in forms)
{
this.SetForms(f);
}
}
/// <summary>
/// 构造函数
/// </summary>
public MagneticForm(bool sign)
{
this.MoveSelf = sign;
InitializeComponent();
}
private void InitializeComponent()
{
this.SuspendLayout();
//
// MagneticForm
//
this.ClientSize = new System.Drawing.Size(292, 266);
this.Name = "MagneticForm";
this.ClientSizeChanged += new System.EventHandler(this.MagneticForm_ClientSizeChanged);
this.Move += new System.EventHandler(this.MagneticForm_Move);
this.ResumeLayout(false);
}
/// <summary>
/// 自身窗体移动事件函数
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MagneticForm_Move(object sender, EventArgs e)
{
this.LeftX = this.Location.X;
this.RightX = this.Location.X + this.Width;
this.TopY = this.Location.Y;
this.BottomY = this.Location.Y + this.Height;
OthersFormMoving();
}