This function can be implemented in VB6 by means of API functions. In vb.net, it can be realized by its own function. First set the form's FormBorderStyle property to none to remove the border from 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.moused Own
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 mouse button to drag the form
If E.button = mousebuttons.left Or E.button = Mousebuttons.right Then
Dim Mousepos as Point = Sender.findform (). MousePosition
' 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 form
Me.close ()
End Sub
End Class
Two, multiple forms call each other
In VB6, multiple forms can be easily invoked between each other, such as: In Form1, a form Form2 can be displayed with just one "form2.show" statement. However, the form processing mechanism has changed a lot in vb.net: Before accessing the form, you must instantiate the form, and if there are multiple code in the project that accesses the same form, you must pass the same instance pointer to the code, otherwise the newly created form instance is no longer the original form.
The following code implements the invocation of forms Form1 and Form2, Form1 as the primary form. The button on the Form1 BtnShowFrm2 is titled "Show Form2," and the Form2 button BtnShowFrm1 is titled "Show Form1."
1, the code in the Form1:
Public Class Form1
Inherits System.Windows.Forms.Form
' Create a new instance of the 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,
' will get the same form instance of Form1.
Frm2.instance (Me)
Frm2.show ()
Me.hide ()
End Sub
End Class
2, the code in the Form2:
Public Class Form2
Inherits System.Windows.Forms.Form
Dim Frm1 as Form1
' Use a new instance property to generate an instance of the form 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
' If Form2 is turned off, the button to set Form1 BtnShowFrm2 is not available.
Frm1. btnshowfrm2.enabled = False
Frm1. Show ()
End Sub
End Class
The above code is all in Windows XP,VB. NET debugging through the
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.