Public X, Y As Integer
10年積累的成都做網(wǎng)站、成都網(wǎng)站設(shè)計、成都外貿(mào)網(wǎng)站建設(shè)經(jīng)驗,可以快速應(yīng)對客戶對網(wǎng)站的新想法和需求。提供各種問題對應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認識你,你也不認識我。但先網(wǎng)站設(shè)計后付款的網(wǎng)站建設(shè)流程,更有江海免費網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
Private Sub Form1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
X = e.X : Y = e.Y
End Sub
Private Sub Form1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
If X = e.X And Y = e.Y Then Exit Sub
If e.Button = Windows.Forms.MouseButtons.Left Then
Me.Left = Me.Left + e.X - X
Me.Top = Me.Top + e.Y - Y
End If
End Sub
1、無邊框窗體也就是無標(biāo)題欄窗體,對于這樣的窗體移動需要編程實現(xiàn)。
2、vb有兩種辦法實現(xiàn),一直接編程實現(xiàn),二調(diào)用windows API編程實現(xiàn)。
3、這里示例直接編程實現(xiàn):
Option?Explicit
Dim?BolIsMove?As?Boolean,?MousX?As?Long,?MousY?As?Long
Private?Sub?Form_MouseDown(Button?As?Integer,?Shift?As?Integer,?X?As?Single,?Y?As?Single)
If?Button?=?1?Then?BolIsMove?=?True
MousX?=?X
MousY?=?Y
End?Sub
Private?Sub?Form_MouseMove(Button?As?Integer,?Shift?As?Integer,?X?As?Single,?Y?As?Single)
Dim?CurrX?As?Long,?CurrY?As?Long
If?BolIsMove?Then
CurrX?=?Me.Left?-?MousX?+?X
CurrY?=?Me.Top?-?MousY?+?Y
Me.Move?CurrX,?CurrY
End?If
End?Sub
Private?Sub?Form_MouseUp(Button?As?Integer,?Shift?As?Integer,?X?As?Single,?Y?As?Single)
BolIsMove?=?False
End?Sub
Imports System Drawing Imports System Windows Forms ****************************************** Private oOriginalRegion As Region = Nothing 用于窗體移動 Private bFormDragging As Boolean = False Private oPointClicked As Point ****************************************** Private Sub Form _MouseDown(ByVal sender As Object ByVal e As System Windows Forms MouseEventArgs) Handles MyBase MouseDown Me bFormDragging = True Me oPointClicked = New Point(e X e Y) End Sub ****************************************** Private Sub Form _MouseUp(ByVal sender As Object ByVal e As System Windows Forms MouseEventArgs) Handles MyBase MouseUp Me bFormDragging = False End Sub ****************************************** Private Sub Form _MouseMove(ByVal sender As Object ByVal e As System Windows Forms MouseEventArgs) Handles MyBase MouseMove If Me bFormDragging Then Dim oMoveToPoint As Point 以當(dāng)前鼠標(biāo)位置為基礎(chǔ) 找出目標(biāo)位置 oMoveToPoint = Me PointToScreen(New Point(e X e Y)) 根據(jù)開始位置作出調(diào)整 oMoveToPoint Offset(Me oPointClicked X * _ (Me oPointClicked Y + _ SystemInformation CaptionHeight + _ SystemInformation BorderSize Height) * ) 移動窗體 Me Location = oMoveToPoint End If
lishixinzhi/Article/program/ASP/201311/21755
1.在mouse事件中實現(xiàn)
2.調(diào)用windows API
實現(xiàn)方式為:
1.在mouse事件中實現(xiàn)
[csharp] view plain copy
Point mouseOff;//鼠標(biāo)移動位置變量
bool leftFlag;//標(biāo)簽是否為左鍵
private void groupControl1_MouseUp(object sender, MouseEventArgs e)
{
if (leftFlag)
{
leftFlag = false;//釋放鼠標(biāo)后標(biāo)注為false;
}
}
private void groupControl1_MouseMove(object sender, MouseEventArgs e)
{
if (leftFlag)
{
Point mouseSet = Control.MousePosition;
mouseSet.Offset(mouseOff.X, mouseOff.Y); //設(shè)置移動后的位置
Location = mouseSet;
}
}
private void groupControl1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
mouseOff = new Point(-e.X, -e.Y); //得到變量的值
leftFlag = true; //點擊左鍵按下時標(biāo)注為true;
}
}
private void groupControl1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
mouseOff = new Point(-e.X, -e.Y); //得到變量的值
leftFlag = true; //點擊左鍵按下時標(biāo)注為true;
}
}
2.調(diào)用windows API
調(diào)用前需要添加using System.Runtime.InteropServices;
[csharp] view plain copy
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
private void groupControl1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ReleaseCapture(); //釋放鼠標(biāo)捕捉
//發(fā)送左鍵點擊的消息至該窗體(標(biāo)題欄)
SendMessage(Handle, 0xA1, 0x02, 0);
}
}
VB中就有呀叫MDI窗體,你選擇“工程—添加MDI窗體”就可以了,然后把你剛剛的FORM1窗體設(shè)為MDI的子窗體就在它的屬性里MDIChild設(shè)為True就可以了
'點擊窗口的任何位置拖動窗體
Dim ctX As Single, ctY As Single
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
ctX = X: ctY = Y
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Me.Left = Me.Left + X - ctX
Me.Top = Me.Top + Y - ctY
End If
End Sub
本文標(biāo)題:vb.net怎么移動窗體 vb窗體移動
文章分享:http://m.kartarina.com/article2/dodedic.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供電子商務(wù)、定制網(wǎng)站、微信小程序、域名注冊、網(wǎng)頁設(shè)計公司、ChatGPT
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)