新聞中心
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 以當前鼠標位置為基礎 找出目標位置 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
創(chuàng)新互聯(lián)公司專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務,包含不限于成都網(wǎng)站設計、網(wǎng)站建設、武陵源網(wǎng)絡推廣、小程序開發(fā)、武陵源網(wǎng)絡營銷、武陵源企業(yè)策劃、武陵源品牌公關、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運營等,從售前售中售后,我們都將竭誠為您服務,您的肯定,是我們最大的嘉獎;創(chuàng)新互聯(lián)公司為所有大學生創(chuàng)業(yè)者提供武陵源建站搭建服務,24小時服務熱線:13518219792,官方網(wǎng)址:www.cdcxhl.com
lishixinzhi/Article/program/ASP/201311/21755
vb.net 無邊框窗體的問題
設置窗體的text為空,設置窗體的controlbox屬性為false,設置窗體的FormBorderStyle 屬性為Sizable,就可以改變窗體大小了,并且可以在任務欄點擊。
VB.NET如何實現(xiàn)無邊框窗體拖動? 如果能指定控件拖動更好 希望能有一點分析 使用VS2015
VB6.0寫的,代碼很簡單,無意中寫成的。應該可以參考。不需要任何api函數(shù)。在無邊框窗體頂部中放入一個label標簽。然后用label的 mouse down 和mouse move事件實現(xiàn)
Dim a, b As Single
Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
a = X
b = Y
End Sub
Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Form1.Move Left + X - a, Top + Y - b
End If
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); //設置移動后的位置
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窗口無邊框 vb設計窗口消失了找不回來
鏈接分享:http://www.dlmjj.cn/article/dohiepi.html