新聞中心
如何移動VB中的無邊框窗體
1、無邊框窗體也就是無標題欄窗體,對于這樣的窗體移動需要編程實現(xiàn)。
創(chuàng)新互聯(lián)建站主營廬山網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,app軟件定制開發(fā),廬山h5微信平臺小程序開發(fā)搭建,廬山網(wǎng)站營銷推廣歡迎廬山等地區(qū)企業(yè)咨詢
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
VB.net怎樣按住鼠標移動無邊框窗體
1.在mouse事件中實現(xiàn)
2.調(diào)用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); //設(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; //點擊左鍵按下時標注為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.調(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(); //釋放鼠標捕捉
//發(fā)送左鍵點擊的消息至該窗體(標題欄)
SendMessage(Handle, 0xA1, 0x02, 0);
}
}
VB.NET 拖動無邊框窗體編程實例
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 以當前鼠標位置為基礎(chǔ) 找出目標位置 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
Vb.net 無邊框窗體如何實現(xiàn)四周陰影? 網(wǎng)上搜到的都是兩邊陰影的,我需要四周陰影
設(shè)置全局變量:
Dim?drag?As?Boolean
Dim?mousex?As?Integer
Dim?mousey?As?Integer
假設(shè)你想拖動的是Panel1控件,以及此控件上的?Label1(用于顯示標題)和PictureBox4(用于顯示圖標):
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
本文標題:vb.net無邊框窗體 vbnet窗體設(shè)計
URL分享:http://biofuelwatch.net/article/doeccio.html