动产... [英] Movable property...

查看:249
本文介绍了动产...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


如何防止用户在运行时移动表单。在

的同时,我想保留我的控制盒并形成

边框。


谢谢,

Douglas ^^

解决方案

你必须创建一个继承自form的新类,然后make all

您的表单继承自此新表单。这是课程:


< WatchForWrapping>


公共类MovableForm

继承System.Windows.Forms .Form


私有m_blnMovable As布局


私有Const WM_NCLBUTTONDOWN As Integer =& HA1

Private Const WM_SYSCOMMAND As Integer =& H112

Private Const HTCAPTION As Integer =& H2

Private Const SC_MOVE As Integer =& HF010


Public Sub New()

MyBase.New()

m_Movable = True

End Sub


< System.ComponentModel.Category(" Behavior"),
System.ComponentModel.Description("允许移动表单)> _

Public Property Movable()As Boolean

获取

返回m_blnMovable

结束获取

设置(ByVal值为布尔值)

m_blnMovable =价值

结束集

结束物业


受保护的覆盖子WndProc(ByRef m As Message)


如果不是m_blnMovable那么

如果m.Msg = WM_SYSCOMMAND并且m.WParam.ToInt32 = SC_MOVE然后

返回

如果m.Msg = WM_NCLBUTTONDOWN而且m.WParam.ToInt32 = HTCAPTION

然后返回

结束如果


MyBase.WndProc(m)


结束次级

结束班级


< / WatchForWrapping>


这会为您的表单添加Movable属性。将其设置为false并且无法移动表单

。该属性将显示在

''行为'部分下的属性浏览器中。请记住:您希望拥有此属性的表单

必须从MovableForm继承,并且必须在您创建此类之后构建项目

在表单可以继承之前。进入代码

并更改表单的Inherits行。为了安全起见,建立你的

项目,然后在设计师中查看表格,并玩你的Movable

财产。


-

HTH,

- Tom Spink,überGeek


请回复新闻组,

所以所有人都可以受益

你好 <做********* @ texwinca.com>在留言中写道

news:07 **************************** @ phx.gbl ... < blockquote class =post_quotes>您好,

如何防止用户在运行时移动表单。在
同时,我想保留我的控制盒并形成边框。

谢谢,
道格拉斯^^



道格拉斯,

这对我有用

\\\\\\\\\ />
Private Sub Form1_Move(ByVal sender As Object,ByVal e As System.EventArgs)

处理MyBase.Move

MyBase.Location = New System.Drawing .Point(30,30)

End Sub

/////////

Cor

嗨汤姆,


好​​一个,我估计我可以在某个时候使用它 - 它会进入我的

片段采集。谢谢。


什么是标签< WatchForWrapping> < / WatchForWrapping> for?

你似乎记得以前用过它。


问候,

Fergus



Hello,

How to prevent user from moving the form at run time. At
the same time, I want to keep my control box and form
border.

Thanks,
Douglas ^^

解决方案

You''ll have to create a new class which inherits from form, then make all
your forms inherit from this new form. Here is the class:

<WatchForWrapping>

Public Class MovableForm
Inherits System.Windows.Forms.Form

Private m_blnMovable As Boolean

Private Const WM_NCLBUTTONDOWN As Integer = &HA1
Private Const WM_SYSCOMMAND As Integer = &H112
Private Const HTCAPTION As Integer = &H2
Private Const SC_MOVE As Integer = &HF010

Public Sub New()
MyBase.New()
m_Movable = True
End Sub

<System.ComponentModel.Category("Behavior"),
System.ComponentModel.Description("Allows the form to be moved")> _
Public Property Movable() As Boolean
Get
Return m_blnMovable
End Get
Set(ByVal Value As Boolean)
m_blnMovable = Value
End Set
End Property

Protected Overrides Sub WndProc(ByRef m As Message)

If Not m_blnMovable Then
If m.Msg = WM_SYSCOMMAND And m.WParam.ToInt32 = SC_MOVE Then
Return
If m.Msg = WM_NCLBUTTONDOWN And m.WParam.ToInt32 = HTCAPTION
Then Return
End If

MyBase.WndProc(m)

End Sub
End Class

</WatchForWrapping>

This adds a Movable property to your form. Set it to false and the form
cannot be moved. The property will appear in the property browser under the
''Behavior'' section. Remember: The forms you would like to have this property
must inherit from MovableForm, and the project must be built after you
create this class before your forms can inherit from it. Go into the code
and change the Inherits line of your form. Just to be safe, build your
project then view the form in the Designer, and play with your Movable
property.

--
HTH,
-- Tom Spink, über Geek

Please respond to the newsgroup,
so all can benefit
"Hello" <do*********@texwinca.com> wrote in message
news:07****************************@phx.gbl...

Hello,

How to prevent user from moving the form at run time. At
the same time, I want to keep my control box and form
border.

Thanks,
Douglas ^^



Douglas,
This works for me
\\\\\\\\
Private Sub Form1_Move(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Move
MyBase.Location = New System.Drawing.Point(30, 30)
End Sub
/////////
Cor


Hi Tom,

Nice one, I reckon I can use that sometime - It''s going into my
snippets collection. Thanks.

What is the tag <WatchForWrapping> </WatchForWrapping> for ?
You''ve used it before I seem to remember.

Regards,
Fergus



这篇关于动产...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆