vb.net无边框缩放,vb无边框窗体

VB.net怎样按住鼠标移动无边框窗体

1.在mouse事件中实现

成都创新互联坚持“要么做到,要么别承诺”的工作理念,服务领域包括:做网站、成都网站制作、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的延安网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!

2.调用windows API

实现方式为:

1.在mouse事件中实现

[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(); //释放鼠标捕捉

//发送左键点击的消息至该窗体(标题栏)

SendMessage(Handle, 0xA1, 0x02, 0);

}

}

VB.NET改变无框窗体大小

改变大小用Me.Width和Me.Height就行了,楼主想问的是允许用户改变无边框窗体的大小吧?

Public Class Form1

Private Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" (ByVal hwnd As Int32, ByVal nIndex As Int32) As Int32

Private Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" (ByVal hwnd As Int32, ByVal nIndex As Int32, ByVal dwNewLong As Int32) As Int32

Private Const GWL_STYLE As Int32 = -16

Private Const WS_THICKFRAME As Int32 = H40000

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None

Dim style As Int32 = GetWindowLong(Me.Handle, GWL_STYLE) Or WS_THICKFRAME

SetWindowLong(Me.Handle, GWL_STYLE, style)

End Sub

End Class

VB 无边框窗体如何改变大小

很简单啊,窗口里放入一个Label1,再把上面的代码复制粘贴到代码窗口,运行即可。鼠标放到窗口右下角的黑色小块(也就是Label1),点住拖动即可任意改变窗体大小了。

VB.NET鼠标拖动无边框窗体改变窗体大小

在VB中,BorderStyle属性为0的窗体没有边框,并且也没有与边框相关的元素。这种窗体具有简洁、占用空间少等优点,用它可以设计出某些富有个性的窗体。但是,由于它没有标题栏,窗体不能移动,同时也不能改变大小,在某些情况下会给使用者造成一定的麻烦。本文介绍在VB中如何用API函数操作无边框窗体。

移动窗体

新建一标准工程,设置Form1的BorderStyle属性为0。此时运行程序后,无法移动窗体。为能移动窗体,在Form1的代码窗口声明下列函数和常数:

Option Explicit

Private Declare Function ReleaseCapture Lib “user32” ()AsLong

Private Declare Function SendMessage Lib “user32”Alias“SendMessageA” (ByVal hwnd As Long, ByVal wMsg As Long,

ByVal wParam As Long, lParam As Any) As Long

Const WM_SYSCOMMAND = H112

Const SC_MOVE = HF012

在Form_MouseDown事件中输入以下代码:

Private Sub Form_MouseDown(Button As Integer, Shift As Integer,XAs Single, Y As Single)

按下鼠标左键

If Button = vbcenterButton Then

为当前的应用程序释放鼠标捕获

ReleaseCapture

移动窗体

SendMessage Me.hwnd, WM_SYSCOMMAND, SC_MOVE, 0

End If

End Sub

注意:此时窗体上不能放置除Shape控件以外的任何控件,否则,在被控件遮住的地方点按鼠标还是无法移动窗体。要使点按控件也能移动窗体,需再添加一个该控件的MouseDown事件过程,代码与上述过程代码相似。

改变窗体的大小

为了改变窗体的大小,需要添加一个Timer控件,以定时捕获鼠标在窗体中的位置。当鼠标位于窗体边缘时,改变鼠标的形状,以通知用户可以进行改变大小的操作。为此,将Timer控件的Interval属性设为100(即每过100毫秒检测一下鼠标位置),其他取默认值。

在Form1的代码窗口中再添加下列两个函数,并定义两个自定义变量和一个字符串变量:

取得窗体位置的函数

Private Declare Function GetWindowRect Lib “user32” (ByVal hwndAsLong, lpRect As RECT) As Long

取得鼠标位置的函数

Private Declare Function GetCursorPos Lib “user32” (lpPointAsPOINTAPI) As Long

鼠标位置变量

Private Type POINTAPI

x As Long

y As Long

End Type

窗体位置变量

Private Type RECT

center As Long

Top As Long

center As Long

Bottom As Long

End Type

所要执行的动作变量,是移动还是改变大小及从哪个方向改变大小

Dim Action As String

在Timer1控件的Timer事件过程中添加以下代码:

Private Sub Timer1_Timer()

Dim MyRect As RECT

Dim MyPoint As POINTAPI

MyRect返回当前窗口位置

Call GetWindowRect(Me.hwnd, MyRect)

MyPoint返回当前鼠标位置

Call GetCursorPos(MyPoint)

Select Case True

鼠标位于窗体左上方

Case MyPoint.x MyRect.center + 5 And MyPoint.y ="" p=""

Screen.MousePointer = vbSizeNWSE

Action = “centerUp”

鼠标位于窗体右下方

Case MyPoint.x MyRect.center - 5 And MyPoint.yMyRect.Bottom - 5

Screen.MousePointer = vbSizeNWSE

Action = “centerDown”

鼠标位于窗体右上方

Case MyPoint.x MyRect.center - 5 And MyPoint.y="" p="" +=""

’45度双向鼠标指针

Screen.MousePointer = vbSizeNESW

Action = “centerUp”

鼠标位于窗体左下方

Case MyPoint.x MyRect.center + 5 And MyPoint.yMyRect.Bottom - 5

Screen.MousePointer = vbSizeNESW

Action = “centerDown”

鼠标位于窗体左边

Case MyPoint.x MyRect.center + 5

水平双向鼠标指针

Screen.MousePointer = vbSizeWE

Action = “center”

鼠标位于窗体右边热门推荐: C++程序设计之四书五经 谈谈JAVA程序的反编译1 2

MyRect.center - 5

Screen.MousePointer = vbSizeWE

Action = “center”

鼠标位于窗体上方

Case MyPoint.y MyRect.Top + 5

垂直双向鼠标指针

Screen.MousePointer = vbSizeNS

Action = “Up”

鼠标位于窗体下方

Case MyPoint.y MyRect.Bottom - 5

Screen.MousePointer = vbSizeNS

Action = “Down”

鼠标位于窗体其他位置

Case Else

默认鼠标指针

Screen.MousePointer = 0

Action = “Move”

End Select

End Sub

当利用SendMessage函数由系统向窗口发送改变大小的信息时,只要将上面移动窗体的语句“SendMessageMe.hwnd,WM_SYSCOMMAND, SC_MOVE, 0”中的第3个参数改为相应的常数即可。

VB中HF001~HF008分别是从左、右、上、左上、右上、下、左下、右下8个方向改变窗体大小的常数。结合移动窗体的代码,将上述Form_MouseDown事件的代码综合如下(也可以把这8个常数声明为自定义常数):

Private Sub Form_MouseDown(Button As Integer, Shift As Integer,xAs Single, y As Single)

按下鼠标左键

If Button = vbcenterButton Then

为当前的应用程序释放鼠标捕获

ReleaseCapture

Select Case Action

Case “center”

SendMessage Me.hwnd, WM_SYSCOMMAND, HF001, 0

Case “center”

SendMessage Me.hwnd, WM_SYSCOMMAND, HF002, 0

Case “Up”

SendMessage Me.hwnd, WM_SYSCOMMAND, HF003, 0

Case “centerUp”

SendMessage Me.hwnd, WM_SYSCOMMAND, HF004, 0

Case “centerUp”

SendMessage Me.hwnd, WM_SYSCOMMAND, HF005, 0

Case “Down”

SendMessage Me.hwnd, WM_SYSCOMMAND, HF006, 0

Case “centerDown”

SendMessage Me.hwnd, WM_SYSCOMMAND, HF007, 0

Case “centerDown”

SendMessage Me.hwnd, WM_SYSCOMMAND, HF008, 0

Case “Move”

SendMessage Me.hwnd, WM_SYSCOMMAND, SC_MOVE, 0

End Select

End If

End Sub

如何正确掌握VB.NET操作缩放图像

在VB.NET操作缩放图像中的显示和保存缩放图像,用到Image和Graphics类,在VSDotNet2K3下面Reference里自动添加了引用System.Drawing,直接用就行。

实现VB.NET操作缩放图像代码如下:DimimgAsImageImage=Image.FromFile

(D:\Image\tstImage.jpg)

''tstImage是原先的图片DimgrfxAsGraphics=Me

.CreateGraphics

grfx.DrawImage(img,0,0,img.Width*

3,img.Height*3)''在Form里显示

DimimgnewAsNewSystem.Drawing.Bitmap

(img,img.Height*3,img.Width*3)

''新建一个放大的图片

imgnew.Save(D:\Image\tstNewImage.jpg,

System.Drawing.Imaging.ImageFormat.Jpeg)

''保存放大后图片

你可以建一个Form,然后在Form里拖进一个Button,把上面的代码放在Button_Click事件里面源码天空

,执行就行了。

对上面VB.NET操作缩放图像代码的解释:

1.要获取Graphics对象只能从某一事件的参数中获取或者使用窗体和控件对象的CreateGraphics方法来获取-----上面代码使用Me.CreateGraphics来引用这个对象。

2.加载一个图片用Image类的FromFile或者FromStream方法

3.用DrawImage来显示一个图片,该方法有30多个重载方法,可以查MSDN了解细节。

4.保存时的一个问题:我们必须先建一个对象,用于存缩放图像。


文章名称:vb.net无边框缩放,vb无边框窗体
分享网址:http://azwzsj.com/article/dsgoccj.html