扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
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 |
Public Class Form1 Inherits System.Windows.Forms.Form '创建Form2的一个新的实例 Dim Frm2 As New Form2() Public Function Instance2(ByVal frm As Form2) Frm2 = frm End Function Private Sub BtnShowFrm2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnShowFrm2.Click '以下语句保证在Form2以及其他窗体中访问Form1时, '都将得到Form1的同一个窗体实例。 Frm2.Instance(Me) Frm2.Show() Me.Hide() End Sub End Class |
Public Class Form2 Inherits System.Windows.Forms.Form Dim frm1 As Form1 '借助一个新增的Instance属性来生成窗体frm1的实例 Public Function Instance(ByVal frm As Form1) frm1 = frm End Function Private Sub BtnShowFrm1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnShowFrm1.Click Me.Hide() frm1.Show() End Sub Private Sub Form2_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed '如果Form2被关闭,则设置Form1的按钮BtnShowFrm2不可用。 frm1.BtnShowFrm2.Enabled = False frm1.Show() End Sub End Class |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者