| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1095 人关注过本帖
标题:[求助]拖动没有边框窗体的问题
只看楼主 加入收藏
ninggang
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:637
专家分:0
注 册:2006-11-1
结帖率:40%
收藏
 问题点数:0 回复次数:5 
[求助]拖动没有边框窗体的问题

Public Class Form1
 Inherits System.Windows.Forms.Form

 Private mouse_offset As Point
 Private Sub form1_MouseDown(ByVal sender As Object, ByVal e As  System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
  mouse_offset = New Point(e.X, e.Y)
 End Sub

Private Sub form1_MouseMove(ByVal Sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
 ’按住鼠标左右键均可拖动窗体
 If e.Button = MouseButtons.Left Or e.Button = MouseButtons.Right Then
  Dim mousePos As Point = Sender.findform().MousePosition 这段虽知道定义了一个点,但后面的代码不清楚
  ’获得鼠标偏移量
  mousePos.Offset(-mouse_offset.X, -mouse_offset.Y)' ‘这个鼠标的偏移量是怎么会事啊?而切前面还有个负号,不懂啊
  ’设置窗体随鼠标一起移动
  Sender.findform().Location = mousePos'这段望高手也解释一下嘛
 End If
End Sub

Private Sub BtnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
 ’关闭窗体
 Me.Close()
End Sub
End Class

搜索更多相关主题的帖子: 边框 拖动 窗体 
2006-11-14 15:02
wangfuli
Rank: 4
等 级:贵宾
威 望:12
帖 子:206
专家分:10
注 册:2005-11-11
收藏
得分:0 

.NET Framework 类库
Control.FindForm 方法
检索控件所在的窗体。

命名空间:System.Windows.Forms
程序集:System.Windows.Forms(在 system.windows.forms.dll 中)

语法

Visual Basic(声明)
Public Function FindForm As Form

Visual Basic(用法)
Dim instance As Control
Dim returnValue As Form

returnValue = instance.FindForm

C#
public Form FindForm ()

C++
public:
Form^ FindForm ()

J#
public Form FindForm ()

JScript
public function FindForm () : Form

返回值
控件所在的 Form。
备注

控件的 Parent 属性值可能与 FindForm 方法返回的 Form 不同。例如,如果 RadioButton 控件包含在 GroupBox 控件中,而 GroupBox 在 Form 上,RadioButton 控件的 Parent 是 GroupBox,GroupBox 控件的 Parent 是 Form。

示例

下面的代码示例查找包含指定按钮的窗体。

Visual Basic 复制代码
' This example uses the Parent property and the Find method of Control to set
' properties on the parent control of a Button and its Form. The example assumes
' that a Button control named button1 is located within a GroupBox control. The
' example also assumes that the Click event of the Button control is connected to
' the event handler method defined in the example.
Private Sub button1_Click(sender As Object, e As System.EventArgs) Handles button1.Click
' Get the control the Button control is located in. In this case a GroupBox.
Dim control As Control = button1.Parent
' Set the text and backcolor of the parent control.
control.Text = "My Groupbox"
control.BackColor = Color.Blue
' Get the form that the Button control is contained within.
Dim myForm As Form = button1.FindForm()
' Set the text and color of the form containing the Button.
myForm.Text = "The Form of My Control"
myForm.BackColor = Color.Red
End Sub

C# 复制代码
// This example uses the Parent property and the Find method of Control to set
// properties on the parent control of a Button and its Form. The example assumes
// that a Button control named button1 is located within a GroupBox control. The
// example also assumes that the Click event of the Button control is connected to
// the event handler method defined in the example.
private void button1_Click(object sender, System.EventArgs e)
{
// Get the control the Button control is located in. In this case a GroupBox.
Control control = button1.Parent;
// Set the text and backcolor of the parent control.
control.Text = "My Groupbox";
control.BackColor = Color.Blue;
// Get the form that the Button control is contained within.
Form myForm = button1.FindForm();
// Set the text and color of the form containing the Button.
myForm.Text = "The Form of My Control";
myForm.BackColor = Color.Red;
}

C++ 复制代码
// This example uses the Parent property and the Find method of Control to set
// properties on the parent control of a Button and its Form. The example assumes
// that a Button control named button1 is located within a GroupBox control. The
// example also assumes that the Click event of the Button control is connected to
// the event handler method defined in the example.
private:
void button1_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
// Get the control the Button control is located in. In this case a GroupBox.
Control^ control = button1->Parent;

// Set the text and backcolor of the parent control.
control->Text = "My Groupbox";
control->BackColor = Color::Blue;

// Get the form that the Button control is contained within.
Form^ myForm = button1->FindForm();

// Set the text and color of the form containing the Button.
myForm->Text = "The Form of My Control";
myForm->BackColor = Color::Red;
}

J# 复制代码
// This example uses the Parent property and the Find method of Control to
// set properties on the parent control of a Button and its Form. The
// example assumes that a Button control named button1 is located within a
// GroupBox control. The example also assumes that the Click event of the
// Button control is connected to the event handler method defined in the
// example.
private void button1_Click(Object sender, System.EventArgs e)
{
// Get the control the Button control is located in.
// In this case a GroupBox.
Control control = button1.get_Parent();

// Set the text and backcolor of the parent control.
control.set_Text("My Groupbox");
control.set_BackColor(Color.get_Blue());

// Get the form that the Button control is contained within.
Form myForm = button1.FindForm();

// Set the text and color of the form containing the Button.
myForm.set_Text("The Form of My Control");
myForm.set_BackColor(Color.get_Red());
} //button1_Click


2006-11-17 08:53
chenjin145
Rank: 1
等 级:禁止访问
帖 子:3922
专家分:0
注 册:2006-7-12
收藏
得分:0 
override wndproc

[url=javascript:alert(1);] [div]fdgfdgfdg\" on\"[/div] [/url]
2006-11-17 09:56
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
收藏
得分:0 
MSDN中可以找到一样的。

飘过~~
2006-11-17 21:14
ninggang
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:637
专家分:0
注 册:2006-11-1
收藏
得分:0 
好奇怪哦,在msdn中找不到也,比如说Sender.findform或Sender.findform()提示记录为0

大家一起努力,共同打造未来!!
2006-11-28 18:30
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
收藏
得分:0 
以下是引用ninggang在2006-11-28 18:30:04的发言:
好奇怪哦,在msdn中找不到也,比如说Sender.findform或Sender.findform()提示记录为0

你查找 Sender 的用法不就行了??


飘过~~
2006-11-28 19:26
快速回复:[求助]拖动没有边框窗体的问题
数据加载中...
 
   



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

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