十年網站開發(fā)經驗 + 多家企業(yè)客戶 + 靠譜的建站團隊
量身定制 + 運營維護+專業(yè)推廣+無憂售后,網站問題一站解決
Public X, Y As Integer
10年積累的成都做網站、成都網站設計、成都外貿網站建設經驗,可以快速應對客戶對網站的新想法和需求。提供各種問題對應的解決方案。讓選擇我們的客戶得到更好、更有力的網絡服務。我雖然不認識你,你也不認識我。但先網站設計后付款的網站建設流程,更有江海免費網站建設讓你可以放心的選擇與我們合作。
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、無邊框窗體也就是無標題欄窗體,對于這樣的窗體移動需要編程實現(xiàn)。
2、vb有兩種辦法實現(xiàn),一直接編程實現(xiàn),二調用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 以當前鼠標位置為基礎 找出目標位置 oMoveToPoint = Me PointToScreen(New Point(e X e Y)) 根據(jù)開始位置作出調整 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.調用windows API
實現(xiàn)方式為:
1.在mouse事件中實現(xiàn)
[csharp] view plain copy
Point mouseOff;//鼠標移動位置變量
bool leftFlag;//標簽是否為左鍵
private void groupControl1_MouseUp(object sender, MouseEventArgs e)
{
if (leftFlag)
{
leftFlag = false;//釋放鼠標后標注為false;
}
}
private void groupControl1_MouseMove(object sender, MouseEventArgs e)
{
if (leftFlag)
{
Point mouseSet = Control.MousePosition;
mouseSet.Offset(mouseOff.X, mouseOff.Y); //設置移動后的位置
Location = mouseSet;
}
}
private void groupControl1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
mouseOff = new Point(-e.X, -e.Y); //得到變量的值
leftFlag = true; //點擊左鍵按下時標注為true;
}
}
private void groupControl1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
mouseOff = new Point(-e.X, -e.Y); //得到變量的值
leftFlag = true; //點擊左鍵按下時標注為true;
}
}
2.調用windows API
調用前需要添加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(); //釋放鼠標捕捉
//發(fā)送左鍵點擊的消息至該窗體(標題欄)
SendMessage(Handle, 0xA1, 0x02, 0);
}
}
VB中就有呀叫MDI窗體,你選擇“工程—添加MDI窗體”就可以了,然后把你剛剛的FORM1窗體設為MDI的子窗體就在它的屬性里MDIChild設為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