vb.net做的无窗口应用程序如何实现移动
作者&投稿:骑点 (若有异议请与网页底部的电邮联系)
求大神指点vb.net怎么写无窗口的应用程序呀~
Imports System.Drawing
Imports System.Windows.Forms
Public Class Form1
'******************************************
Private oOriginalRegion As Region = Nothing
' 用于窗体移动
Private bFormDragging As Boolean = False
Private oPointClicked As Point
'******************************************
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
Me.bFormDragging = True
Me.oPointClicked = New Point(e.X, e.Y)
End Sub
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
If Me.bFormDragging Then
Dim oMoveToPoint As Point
' 以当前鼠标位置为基础,找出目标位置
oMoveToPoint = Me.PointToScreen(New Point(e.X, e.Y))
' 根据开始位置作出调整
oMoveToPoint.Offset(Me.oPointClicked.X * -1, _
(Me.oPointClicked.Y + _
SystemInformation.CaptionHeight + _
SystemInformation.BorderSize.Height) * -1)
' 移动窗体
Me.Location = oMoveToPoint
End If
End Sub
Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
Me.bFormDragging = False
End Sub
End Class
要选择控制台应用程序,那个是无界面的;
VB6.0写的,代码很简单,无意中写成的。应该可以参考。不需要任何api函数。在无边框窗体顶部中放入一个label标签。然后用label的 mouse down 和mouse move事件实现Dim a, b As SinglePrivate Sub Label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)a = Xb = YEnd SubPrivate Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)If Button = 1 ThenForm1.Move Left + X - a, Top + Y - bEnd IfEnd Sub
'我试过可以,你试试Imports System.Drawing
Imports System.Windows.Forms
Public Class Form1
'******************************************
Private oOriginalRegion As Region = Nothing
' 用于窗体移动
Private bFormDragging As Boolean = False
Private oPointClicked As Point
'******************************************
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
Me.bFormDragging = True
Me.oPointClicked = New Point(e.X, e.Y)
End Sub
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
If Me.bFormDragging Then
Dim oMoveToPoint As Point
' 以当前鼠标位置为基础,找出目标位置
oMoveToPoint = Me.PointToScreen(New Point(e.X, e.Y))
' 根据开始位置作出调整
oMoveToPoint.Offset(Me.oPointClicked.X * -1, _
(Me.oPointClicked.Y + _
SystemInformation.CaptionHeight + _
SystemInformation.BorderSize.Height) * -1)
' 移动窗体
Me.Location = oMoveToPoint
End If
End Sub
Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
Me.bFormDragging = False
End Sub
End Class
《vb.net创建没有窗体的应用》
答:软件bug。vb.net创建是会有窗体进行应用的,没有应用就是软件bug原因,需要用户将软件关闭,点击系统修复下载,再打开软件即可。