Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement form Operation by VB.NET

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail how to implement the form operation of VB.NET. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

1. How to drag a VB.NET form without borders?

In VB6, this function can only be realized with the help of API function. In VB.NET, it can be realized by its own function. First set the FormBorderStyle property of the form to none to remove the border of the form, and then add a button to the form.

The code in the form is as follows:

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 'hold down the left and right mouse button to drag the form If e.Button = MouseButtons.Left Or e.Button = MouseButtons.Right Then Dim mousePos As Point = Sender.findform () .MousePosition' to get the mouse offset mousePos.Offset (- mouse_offset.X -mouse_offset.Y) 'set the form to move with the mouse 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' close the form Me.Close () End Sub End Class

Second, multiple forms call each other

In VB6, multiple forms can easily call each other, for example: in Form1, you only need a "Form2.Show" statement to display the form Form2. In VB.NET, however, the form handling mechanism has changed a lot: before accessing the form, you must instantiate the form; if there are multiple code in the project that accesses the same form, you must pass its same instance pointer to the code, otherwise the newly created form instance will no longer be the original form.

The following code implements the mutual call between the form Form1 and Form2, with Form1 as the main form. The title of the button BtnShowFrm2 on Form1 is "Show Form2", and the title of button BtnShowFrm1 on Form2 is "Show Form1".

1. The code in Form1:

Public Class Form1 Inherits System.Windows.Forms.Form 'create a new instance of 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' the following statement guarantees that when you access Form1 in Form2 and other forms, you will get the same form instance of Form1. Frm2.Instance (Me) Frm2.Show () Me.Hide () End Sub End Class

2. The code in Form2:

Public Class Form2 Inherits System.Windows.Forms.Form Dim frm1 As Form1 'generates an instance of the form frm1 Public Function Instance (ByVal frm As Form1) frmfrm1 = 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) with a new Instance property ByVal e As System.EventArgs) Handles MyBase.Closed'if Form2 is shut down The button BtnShowFrm2 that sets Form1 is not available. Frm1.BtnShowFrm2.Enabled = False frm1.Show () End Sub End Class on "how to achieve form operation VB.NET" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it out for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report