<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[FalconIA's BLOG]]></title> 
<link>http://falconia.org/blog/index.php</link> 
<description><![CDATA[FalconIA's Studio]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[FalconIA's BLOG]]></copyright>
<item>
<link>http://falconia.org/blog/post//</link>
<title><![CDATA[VB.NET窗体操作技巧两则]]></title> 
<author>FalconIA &lt;falcon_ia@hotmail.com&gt;</author>
<category><![CDATA[技术杂烩]]></category>
<pubDate>Thu, 26 Jan 2006 03:18:26 +0000</pubDate> 
<guid>http://falconia.org/blog/post//</guid> 
<description>
<![CDATA[ 
	<strong>作　者：刘红军 刘乐坤<br/>引用自：<a href="http://www.5ivb.net/Info/89/Info31156/" target="_blank">http://www.5ivb.net/Info/89/Info31156/</a></strong><br/><br/>目录<br/>一、如何拖动没有边框的窗体？<br/>二、多个窗体之间互相调用<br/><hr/><br/><br/>　　一、如何拖动没有边框的窗体？<br/><br/>　　这个功能在VB6中，需要借助于API函数才能实现。而在VB.NET中，凭自己的功能就能实现。首先设置窗体的FormBorderStyle属性为none以去掉窗体的边框，然后在窗体上添加一个按钮。窗体中的代码如下：<br/><div class="code">Public Class Form1<br/>　Inherits System.Windows.Forms.Form<br/><br/>　Private mouse_offset As Point<br/>　Private Sub form1_MouseDown(ByVal sender As Object, ByVal e As 　System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown<br/>　　mouse_offset = New Point(e.X, e.Y)<br/>　End Sub<br/><br/>Private Sub form1_MouseMove(ByVal Sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove<br/>　&#039;&#039;按住鼠标左右键均可拖动窗体<br/>　If e.Button = MouseButtons.Left Or e.Button = MouseButtons.Right Then<br/>　　Dim mousePos As Point = Sender.findform().MousePosition<br/>　　&#039;&#039;获得鼠标偏移量<br/>　　mousePos.Offset(-mouse_offset.X, -mouse_offset.Y)<br/>　　&#039;&#039;设置窗体随鼠标一起移动<br/>　　Sender.findform().Location = mousePos<br/>　End If<br/>End Sub<br/><br/>Private Sub BtnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br/>　&#039;&#039;关闭窗体<br/>　Me.Close()<br/>End Sub<br/>End Class </div><br/><br/>　　 二、多个窗体之间互相调用<br/><br/>　　在VB6中，多个窗体之间可以很方便地互相调用，如：在Form1中，只需要用一条“Form2.Show” 语句就能显示窗体Form2。然而在VB.NET中窗体处理机制发生了很大的变化：在访问窗体之前，你必须进行窗体实例化；如果在项目中有多处代码访问同一窗体，则你必须把它的同一实例指针传递给这些代码，否则新创建的窗体实例就不再是原先的窗体了。<br/><br/>　　下面的代码实现窗体Form1和Form2之间互相调用,Form1为主窗体。Form1上的按钮BtnShowFrm2的标题为“显示Form2”，Form2上的按钮BtnShowFrm1的标题为“显示Form1”。<br/><br/>　　1、Form1中的代码：<br/><div class="code">Public Class Form1<br/>Inherits System.Windows.Forms.Form<br/>&#039;&#039;创建Form2的一个新的实例<br/>Dim Frm2 As New Form2()<br/><br/>Public Function Instance2(ByVal frm As Form2)<br/>Frm2 = frm<br/>End Function<br/><br/>Private Sub BtnShowFrm2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnShowFrm2.Click<br/>&#039;&#039;以下语句保证在Form2以及其他窗体中访问Form1时，<br/>&#039;&#039;都将得到Form1的同一个窗体实例。<br/>Frm2.Instance(Me)<br/>Frm2.Show()<br/>Me.Hide()<br/>End Sub<br/><br/>End Class</div><br/><br/>　　2、Form2中的代码：<br/><div class="code">Public Class Form2<br/>　Inherits System.Windows.Forms.Form<br/>　Dim frm1 As Form1<br/>　&#039;&#039;借助一个新增的Instance属性来生成窗体frm1的实例<br/>　Public Function Instance(ByVal frm As Form1)<br/>　　frm1 = frm<br/>　End Function<br/><br/>　Private Sub BtnShowFrm1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 　　　Handles BtnShowFrm1.Click<br/>　　Me.Hide()<br/>　　frm1.Show()<br/>　End Sub<br/><br/>　Private Sub Form2_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles 　MyBase.Closed<br/>　　&#039;&#039;如果Form2被关闭，则设置Form1的按钮BtnShowFrm2不可用。<br/>　　frm1.BtnShowFrm2.Enabled = False<br/>　　frm1.Show()<br/>　End Sub<br/>End Class </div><br/>Tags - <a href="http://falconia.org/blog/tags/%25E7%25BC%2596%25E7%25A8%258B/" rel="tag">编程</a> , <a href="http://falconia.org/blog/tags/vb.net/" rel="tag">vb.net</a>
]]>
</description>
</item><item>
<link>http://falconia.org/blog/post//#blogcomment</link>
<title><![CDATA[[评论] VB.NET窗体操作技巧两则]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://falconia.org/blog/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>