1、無邊框窗體也就是無標(biāo)題欄窗體,對(duì)于這樣的窗體移動(dòng)需要編程實(shí)現(xiàn)。
創(chuàng)新互聯(lián)建站主營(yíng)廬山網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,app軟件定制開發(fā),廬山h5微信平臺(tái)小程序開發(fā)搭建,廬山網(wǎng)站營(yíng)銷推廣歡迎廬山等地區(qū)企業(yè)咨詢
2、vb有兩種辦法實(shí)現(xiàn),一直接編程實(shí)現(xiàn),二調(diào)用windows API編程實(shí)現(xiàn)。
3、這里示例直接編程實(shí)現(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
1.在mouse事件中實(shí)現(xiàn)
2.調(diào)用windows API
實(shí)現(xiàn)方式為:
1.在mouse事件中實(shí)現(xiàn)
[csharp] view plain copy
Point mouseOff;//鼠標(biāo)移動(dòng)位置變量
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è)置移動(dòng)后的位置
Location = mouseSet;
}
}
private void groupControl1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
mouseOff = new Point(-e.X, -e.Y); //得到變量的值
leftFlag = true; //點(diǎn)擊左鍵按下時(shí)標(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; //點(diǎn)擊左鍵按下時(shí)標(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ā)送左鍵點(diǎn)擊的消息至該窗體(標(biāo)題欄)
SendMessage(Handle, 0xA1, 0x02, 0);
}
}
Imports System Drawing Imports System Windows Forms ****************************************** Private oOriginalRegion As Region = Nothing 用于窗體移動(dòng) 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) * ) 移動(dòng)窗體 Me Location = oMoveToPoint End If
lishixinzhi/Article/program/ASP/201311/21755
設(shè)置全局變量:
Dim?drag?As?Boolean
Dim?mousex?As?Integer
Dim?mousey?As?Integer
假設(shè)你想拖動(dòng)的是Panel1控件,以及此控件上的?Label1(用于顯示標(biāo)題)和PictureBox4(用于顯示圖標(biāo)):
Private?Sub?TitleMove_MouseDown(sender?As?Object,?e?As?System.Windows.Forms.MouseEventArgs)?Handles?Panel1.MouseDown,?Label1.MouseDown,?PictureBox4.MouseDown
drag?=?True
mousex?=?Windows.Forms.Cursor.Position.X?-?Me.Left
mousey?=?Windows.Forms.Cursor.Position.Y?-?Me.Top
End?Sub
Private?Sub?TitleMove_MouseMove(sender?As?Object,?e?As?System.Windows.Forms.MouseEventArgs)?Handles?Panel1.MouseMove,?Label1.MouseMove,?PictureBox4.MouseMove
If?drag?Then
Me.Top?=?Windows.Forms.Cursor.Position.Y?-?mousey
Me.Left?=?Windows.Forms.Cursor.Position.X?-?mousex
End?If
End?Sub
Private?Sub?TitleMove_MouseUp(sender?As?Object,?e?As?System.Windows.Forms.MouseEventArgs)?Handles?Panel1.MouseUp,?Label1.MouseUp,?PictureBox4.MouseUp
drag?=?False
End?Sub
網(wǎng)站標(biāo)題:vb.net無邊框窗體 vbnet窗體設(shè)計(jì)
文章出自:http://muchs.cn/article0/doeccio.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導(dǎo)航、建站公司、服務(wù)器托管、網(wǎng)站導(dǎo)航、用戶體驗(yàn)、企業(yè)建站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容