200分!! 如何实现vs.net解决方案、属性窗体那样的磁性吸附窗体?

MyLf 2005-09-01 04:55:39
百度了一下,没有看到用.Net实现的,好多都是用Delphi实现的,但俺不懂Delphi。
...全文
406 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
tianjh 2005-09-12
  • 打赏
  • 举报
回复
??
冷锋 2005-09-03
  • 打赏
  • 举报
回复
Mark
xamaizi 2005-09-03
  • 打赏
  • 举报
回复
在www.codeproject.com上搜索dockpanel,带源码的
MyLf 2005-09-03
  • 打赏
  • 举报
回复
"VS.NET编辑器中的那种磁性吸附没有多少技可言" ??兄弟,你自己去实现看看?

半透明的点阵条?应该就是普通的拖拽功能加上GDI+实现,大凡拖拽操作都不是拖拽真正的本身窗体的。
houyunqing 2005-09-03
  • 打赏
  • 举报
回复
跟着上面的朋友问一句:我觉得实现VS.NET编辑器中的那种磁性吸附没有多少技可言,可是,那种半透明的点阵条该怎么搞定呢?就当他好看吧,我觉得也确实是很有用的东西,起码不会在Mouse移动的时候拖动的那个窗口一个劲地颤抖
MyLf 2005-09-03
  • 打赏
  • 举报
回复
to:bomb_boy(梦之星),十分的感谢!其实我并不是向大家计源代码,我也是在问如果实现。你所说的方法是Winamp那样的东东,而我是要vs.net下的解决方案资源管理器和属性窗口那样的窗口。
不过,你的结束语未免说得偏激了些,先把微软放到一边,单就.Net来说真是是不错啊,只是现在的Java太火了,看到那些个招聘信息Java占了大部份,心里也是那个着急,但我从不否认.Net,仍然喜欢着呢。

DockPanel 真不错,现在才知道有这样的好东东。

看到外国人写的这两个.Net组件(dotnetmagic、DockPanel),心里好生佩服。也不由得把自己的.Net水平重新评估一下,虽然.net很“庞大”,但自认为自己的.Net还算过得去,但看到人家写的东西,心里没有了底,惭愧呢。
这组件设计还得好好研究一下下。。。
bomb_boy 2005-09-02
  • 打赏
  • 举报
回复
代码二(主窗口,就是用来悬浮其它窗口的窗口)F1.cs
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace WT
{
/// <summary>
/// F1 的摘要说明。
/// </summary>
public class F1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public F1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 0);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(216, 136);
this.label1.TabIndex = 0;
this.label1.Text = "主窗体,分窗口吸引后自动跟随拖动";
//
// F1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(208, 101);
this.Controls.Add(this.label1);
this.Name = "F1";
this.Text = "F1";
this.Load += new System.EventHandler(this.F1_Load);
this.Move += new System.EventHandler(this.F1_Move);
this.ResumeLayout(false);

}
#endregion

private void F1_Load(object sender, System.EventArgs e)
{

}

private void F1_Move(object sender, System.EventArgs e)
{
fMain.sum();
}
}
}


分窗口F2.cs
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace WT
{
/// <summary>
/// F2 的摘要说明。
/// </summary>
public class F2 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public F2()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 8);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(216, 160);
this.label1.TabIndex = 0;
this.label1.Text = "分窗体,被主窗口吸引后,自动跟随";
//
// F2
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(208, 165);
this.Controls.Add(this.label1);
this.Name = "F2";
this.Text = "F2";
this.Move += new System.EventHandler(this.F2_Move);
this.ResumeLayout(false);

}
#endregion

private void F2_Move(object sender, System.EventArgs e)
{
fMain.sum2();
}
}
}


全部玩了,只完成了2个窗口间的磁性关系,3个4个都一会是,只是增加代码长度,编码除了敲代码水平外,关键还要看会不会分析然后根据分析写代码如果别人分析了原理自己还写不出来代码,就是自己缺乏一种东西了.
(我个人觉得问什么怎么实现能不能给代码,正确的问发是这个东西怎么实现的,原理是什么,然后写出代码来和大家交流不是光看代码,所以我回问题,很少贴代码,就当自己去实现一次,看看我的实现原理和我说的有区别吗,看看代码,是不是瞒难.不就是坐标问题吗,一点技术含量都冒得,自己都贴出来丢脸了,随便B4一下微软,什么.NET计划,完全让我们上贼船,现在都难下来了.)
bomb_boy 2005-09-02
  • 打赏
  • 举报
回复
没有那简单,自己看代码,刚写的
三个页面,一个主监控页面
一个主页面,一个跟随页面
代码如下,代码没有怎么整理,肯定写的不台好看,目的只是证明方法是否可行.
代码一
主监控窗口fMain.cs
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace WT
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class fMain : System.Windows.Forms.Form
{
private static bool islian=false;//是否被吸引住
private static int liantype;//吸引方向
private static int cxmax=20;//磁性距离最大距离正值
private static int cxmin=-20;//磁性距离最大距离负值
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
private static Form f1=new F1();
private System.Windows.Forms.Label label1;
private static Form f2=new F2();
public fMain()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 8);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(280, 48);
this.label1.TabIndex = 1;
this.label1.Text = "监控窗口,本窗口内处理吸引事件.";
//
// fMain
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 29);
this.Controls.Add(this.label1);
this.Name = "fMain";
this.Text = "Main";
this.Load += new System.EventHandler(this.fMain_Load);
this.ResumeLayout(false);

}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new fMain());

}
private void button1_Click(object sender, System.EventArgs e)
{


}

private void fMain_Load(object sender, System.EventArgs e)
{
f1.Show();
f2.Show();
}
//主窗口计算悬浮
public static void sum(){
if (islian)
{
switch(liantype)
{
case 1:
f2.SetDesktopLocation(f1.DesktopLocation.X,f1.DesktopLocation.Y+f1.Height);
break;
case 2:
f2.SetDesktopLocation(f1.DesktopLocation.X,f1.DesktopLocation.Y-f2.Height);
break;
case 3:
f2.SetDesktopLocation(f1.DesktopLocation.X-f2.Width,f1.DesktopLocation.Y);
break;
case 4:
f2.SetDesktopLocation(f1.DesktopLocation.X+f2.Width,f1.DesktopLocation.Y);
break;

}
}
else
{
xuafu();

}



}
//悬浮识别处理
public static void xuafu(){
int x;
int y;

//处理下边磁性
x=f1.DesktopLocation.X;
y=f1.DesktopLocation.Y+f1.Height;
if ((x-f2.DesktopLocation.X<cxmax&&x-f2.DesktopLocation.X>cxmin)&&(y-f2.DesktopLocation.Y<cxmax&&y-f2.DesktopLocation.Y>cxmin))
{
f2.SetDesktopLocation(x,y);
islian=true;
liantype=1;
}
else{islian=false;}
//处理上边磁性
x=f1.DesktopLocation.X;
y=f1.DesktopLocation.Y;
if((x-f2.DesktopLocation.X<cxmax&&x-f2.DesktopLocation.X>cxmin)&&(y-f2.DesktopLocation.Y-f2.Height<cxmax&&y-f2.DesktopLocation.Y-f2.Height>cxmin))
{
f2.SetDesktopLocation(x,y-f2.Height);
islian=true;
liantype=2;
}
//处理左边磁性
x=f1.DesktopLocation.X;
y=f1.DesktopLocation.Y;
if((x-f2.DesktopLocation.X-f2.Width<cxmax&&x-f2.DesktopLocation.X-f2.Width>cxmin)&&(y-f2.DesktopLocation.Y<cxmax&&y-f2.DesktopLocation.Y>cxmin))
{
f2.SetDesktopLocation(x-f2.Width,y);
islian=true;
liantype=3;
}
//处理右边磁性
x=f1.DesktopLocation.X+f1.Width;
y=f1.DesktopLocation.Y;
if((x-f2.DesktopLocation.X<cxmax&&x-f2.DesktopLocation.X>cxmin)&&(y-f2.DesktopLocation.Y<cxmax&&y-f2.DesktopLocation.Y>cxmin))
{
f2.SetDesktopLocation(x,y);
islian=true;
liantype=4;
}
}
//分窗口计算悬浮
public static void sum2()
{

xuafu();
}





}
}


web_gus 2005-09-02
  • 打赏
  • 举报
回复
DockPanel
搜索一下,有源代码
zeusvenus 2005-09-01
  • 打赏
  • 举报
回复
楼主可以关注下智能客户端的智能文档,有类似的东西。
newgrammer 2005-09-01
  • 打赏
  • 举报
回复
关注
lionelwy 2005-09-01
  • 打赏
  • 举报
回复
up
Alden 2005-09-01
  • 打赏
  • 举报
回复
不太清楚
MyLf 2005-09-01
  • 打赏
  • 举报
回复
我所说的是磁性吸附,是子窗体和主窗体之间的关系。

dotnetmagic的我看了一下,挺不错,不过,移动窗体时有点夸张。。。

注:我不要第三方控件。

to bomb_boy(梦之星) :没有你说的那么简单吧。
bomb_boy 2005-09-01
  • 打赏
  • 举报
回复
文字写多了,本来是一楼的居然跑5楼了,郁闷.
bomb_boy 2005-09-01
  • 打赏
  • 举报
回复
我没有去刻意去实现,但是N年前用VB实现过,不管用什么软件实现,大概思路基本一样.
一,记录每个窗口的大小,和在屏幕中的坐标.(可以实现)
二.移动的时候计算2个窗体的四周之间的距离(通过上面一步的数据可以算出来)
三.当距离在一定的范围内,也就是那个磁性的范围,直接将窗体的在屏幕上的位置进行更改,该成一个与周围相连接的坐标.同时记录这2个窗体是连接的.这样移动主窗体,周围的小窗体也一起移动.(看起来难,其实简单的很)这一步还可以作出效果,因为突然改变坐标位置肯定感觉不好,所以改变坐标的时候用移动的方法比较好,而且不是直接移动到位,是1个或2个象素的移动,这样才有好看的效果.
iloveyour 2005-09-01
  • 打赏
  • 举报
回复
共一下吧
JasonHeung 2005-09-01
  • 打赏
  • 举报
回复
net的不是吧?Winamp的才是。其实就是你定义个主窗体,跟踪和控制子窗体的位置。
pignut_wang 2005-09-01
  • 打赏
  • 举报
回复
有写好的控件
要的话加我:43441383
说要控件
abiho 2005-09-01
  • 打赏
  • 举报
回复
用dotnetmagic,很好用

110,532

社区成员

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

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

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