| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 926 人关注过本帖
标题:一个窗体的问题
只看楼主 加入收藏
leisky
Rank: 1
等 级:新手上路
帖 子:253
专家分:0
注 册:2006-5-22
结帖率:100%
收藏
 问题点数:0 回复次数:14 
一个窗体的问题
请问一下如果把窗体的FormBorderStyle 属性设为 None
怎么用代码来实现用鼠标来拉动窗体的大小
就是当鼠标放在窗体的边缘时改变鼠标的样式.并能来拉动窗体的大小..有急用..请高手指点..在线等
搜索更多相关主题的帖子: 窗体 鼠标 属性 None 样式 
2006-08-17 13:44
chenjin145
Rank: 1
等 级:禁止访问
帖 子:3922
专家分:0
注 册:2006-7-12
收藏
得分:0 
MouseMove裡面

if(e.X>=0&&e.X<=2)
{
Cursor.Current=Cursors.SizeWE;
if(down)
再調整form size
}

Mousedown
if(e.X>=0&&e.X<=2&&Cursor.Current==Cursors.SizeWE)
{
down=true
}

Mouseup
down=false

[url=javascript:alert(1);] [div]fdgfdgfdg\" on\"[/div] [/url]
2006-08-17 14:22
leisky
Rank: 1
等 级:新手上路
帖 子:253
专家分:0
注 册:2006-5-22
收藏
得分:0 
楼主..能不能给一个具体的代码.了..小弟是新手.

请问" 再調整form size "

这里的代码是什么?


2006-08-17 14:52
chenjin145
Rank: 1
等 级:禁止访问
帖 子:3922
专家分:0
注 册:2006-7-12
收藏
得分:0 
你去寫代碼實現啊
有個思路就行了

就是結合form裡面的mousemove mousedown mouseup三個事件來實現

if(e.X>=0&&e.X<=2) //這樣判斷鼠標是否在form的左邊緣 e.y>=0&&e.y<=2上邊緣 form.size.width右邊緣
{
Cursor.Current=Cursors.SizeWE;
if(判斷有沒按下鼠標)
這裡就可以根據鼠標移動來設置form的大小
}

[url=javascript:alert(1);] [div]fdgfdgfdg\" on\"[/div] [/url]
2006-08-17 15:06
noshow
Rank: 2
等 级:新手上路
威 望:4
帖 子:1127
专家分:0
注 册:2006-4-21
收藏
得分:0 
请不要怪我太坦白
如果你不设置的话
窗体默认的可以随便拉的

此号自封于2006年11月30日
2006-08-17 15:12
chenjin145
Rank: 1
等 级:禁止访问
帖 子:3922
专家分:0
注 册:2006-7-12
收藏
得分:0 

設置了比較好看


[url=javascript:alert(1);] [div]fdgfdgfdg\" on\"[/div] [/url]
2006-08-17 15:13
leisky
Rank: 1
等 级:新手上路
帖 子:253
专家分:0
注 册:2006-5-22
收藏
得分:0 

问题是我现在要设计的这个窗体是不用窗体自代的那个外关的...呵呵


2006-08-18 09:15
leisky
Rank: 1
等 级:新手上路
帖 子:253
专家分:0
注 册:2006-5-22
收藏
得分:0 

谢谢楼主..不过不是用的你那种方法..代码帖出..与大家共享

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

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

public Form3()
{
//
// 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()
{
//
// Form3
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 266);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "Form3";
this.Text = "Form3";
this.Load += new System.EventHandler(this.Form3_Load);

}
#endregion

private const int WM_NCHITTEST = 0x84; //移动鼠标,按住或释放鼠标时发生的系统消息
private const int HTCLIENT = 0x1;//工作区
private const int HTSYSMENU = 3;//系统菜单
private const int HTCAPTION = 0x2; //标题栏

private const int HTLEFT = 10;//向左
private const int HTRIGHT = 11;//向右
private const int HTTOP = 12;//向上
private const int HTTOPLEFT = 13;//向左上
private const int HTTOPRIGHT = 14;//向右上
private const int HTBOTTOM = 15;//向下
private const int HTBOTTOMLEFT = 16;//向左下
private const int HTBOTTOMRIGHT = 17;//向右下

private const int BorderWidth = 5;//自己定义的窗体边的宽度

//可以调整窗体的大小和移动窗体的位置
protected override void WndProc(ref Message m)
{
switch(m.Msg)
{
case WM_NCHITTEST:
base.WndProc(ref m);
if (DesignMode)
{
return;
}

if ((int)m.Result == HTCLIENT)//在客户区
if ((Cursor.Position.X<=this.Left + BorderWidth) && (Cursor.Position.Y <= this.Top + BorderWidth))
m.Result = (IntPtr)HTTOPLEFT;//左上
else if ((Cursor.Position.X>=this.Left + this.Width-BorderWidth) && (Cursor.Position.Y<=this.Top +BorderWidth))
m.Result = (IntPtr)HTTOPRIGHT;//右上
else if ((Cursor.Position.X <= this.Left + BorderWidth) && (Cursor.Position.Y>=this.Top + this.Height-BorderWidth))
m.Result = (IntPtr)HTBOTTOMLEFT;//左下
else if ((Cursor.Position.X>=this.Left + this.Width-BorderWidth) && (Cursor.Position.Y>=this.Top + this.Height-BorderWidth))
m.Result = (IntPtr)HTBOTTOMRIGHT;//右下
else if (Cursor.Position.X<=this.Left + BorderWidth)
m.Result = (IntPtr)HTLEFT;//左
else if (Cursor.Position.X>=this.Left + this.Width-BorderWidth)
m.Result = (IntPtr)HTRIGHT;//右
else if (Cursor.Position.Y<=this.Top + BorderWidth)
m.Result = (IntPtr)HTTOP;//上
else if (Cursor.Position.Y>=this.Top + this.Height-BorderWidth)
m.Result = (IntPtr)HTBOTTOM;//下
else if (Cursor.Position.Y<=this.Top + BorderWidth + 10 )
{
if (Cursor.Position.X<=this.Left + this.Width-BorderWidth + 10)
{
m.Result = (IntPtr)HTSYSMENU;//系统菜单,可以在这里双击鼠标关闭窗体。
}
}
else
m.Result = (IntPtr)HTCAPTION;//移动窗体,双击可以最大化窗体或还原。
return;
default:
base.WndProc(ref m);
break;
}
}

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

}
}
}


2006-08-18 10:40
noshow
Rank: 2
等 级:新手上路
威 望:4
帖 子:1127
专家分:0
注 册:2006-4-21
收藏
得分:0 
顶一个
谢谢分享
学习中

此号自封于2006年11月30日
2006-08-18 11:13
chenjin145
Rank: 1
等 级:禁止访问
帖 子:3922
专家分:0
注 册:2006-7-12
收藏
得分:0 
非常感謝
很好的東西
原來WndProc方法可以獲取 設置窗口消息

[url=javascript:alert(1);] [div]fdgfdgfdg\" on\"[/div] [/url]
2006-08-18 11:24
快速回复:一个窗体的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016768 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved