【分享】 疯狂的 Form

happyer_longlong 2010-08-28 01:45:03
前两天看到这个帖子 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();
}
...全文
525 78 打赏 收藏 转发到动态 举报
写回复
用AI写文章
78 条回复
切换为时间正序
请发表友善的回复…
发表回复
sunjuncai 2010-08-30
  • 打赏
  • 举报
回复
很不错!
rabbit5 2010-08-30
  • 打赏
  • 举报
回复
收藏,有空儿学习一下:)
FlyBee 2010-08-30
  • 打赏
  • 举报
回复
[Quote=引用楼主 happyer_longlong 的回复:]
疯狂的Form主类
[/Quote]
貌似没写成类哦
tyi20 2010-08-30
  • 打赏
  • 举报
回复
围观 ···
tone770 2010-08-30
  • 打赏
  • 举报
回复
ls3aslp 2010-08-30
  • 打赏
  • 举报
回复
谢谢分享
gaomeng320 2010-08-30
  • 打赏
  • 举报
回复
what?
留个名先
sunnj87 2010-08-30
  • 打赏
  • 举报
回复
下来看看!
haifeng39 2010-08-30
  • 打赏
  • 举报
回复
学习~
rinoya111 2010-08-30
  • 打赏
  • 举报
回复
谢谢分享
银-魂 2010-08-30
  • 打赏
  • 举报
回复
有意思,给我留言 上班就来看了 呵呵 不过我已经做好了
现在也没时间做WinForm
天地英豪 2010-08-30
  • 打赏
  • 举报
回复
mark
study
Jck 2010-08-30
  • 打赏
  • 举报
回复
接分围观
a78782295 2010-08-30
  • 打赏
  • 举报
回复
学习! 都挺疯狂的 呵呵
ICANNER 2010-08-30
  • 打赏
  • 举报
回复
支持分享
huwen7565833 2010-08-30
  • 打赏
  • 举报
回复
支持lz 接分!!
happyer_longlong 2010-08-29
  • 打赏
  • 举报
回复
咋都没人提提怎么改进,期待高手
happyer_longlong 2010-08-29
  • 打赏
  • 举报
回复
[Quote=引用 38 楼 computerfox 的回复:]
不错,自己写的吗!
阿捷
[/Quote]
是自己写的 原始帖子用 委托,发现需要传个实例过去,于是索性就改成了观察者模式
chenhansong2008 2010-08-29
  • 打赏
  • 举报
回复
qlzf11140820 2010-08-29
  • 打赏
  • 举报
回复
接 分
加载更多回复(53)

110,565

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧