网站导航免费论文 原创论文 论文搜索 原创论文 网学软件 学术大家 资料中心 会员中心 问题解答 原创论文 论文素材 设计下载 最新论文 下载排行 论文上传 在线投稿 联系我们
返回网学首页
网学联系
最新论文 推荐专题 热门论文 素材专题
当前位置: 网学 > 编程文档 > VB.net > 正文
从VB 6到VB.NET-不规则窗体特殊应用
来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 12/10/15
下载{$ArticleTitle}原创论文样式
me!"

End If

End If

End Sub

''如果还要屏蔽Alt+F4,加上

Private Sub Form_QueryUnload(ByVal Cancel As Integer, ByVal UnloadMode As Integer)

Cancel = 1

End Sub

在VB.NET中,这次需要借助API了,因为系统没有提供这样的类,这个例子,同时给大家提供了一个API的使用范例。(因为系统类库包装了绝大部分API,所以不推荐使用)

以下是VB.NET的代码:

''API声明

Private Declare Function GetSystemMenu Lib "User32" (ByVal hwnd As Integer, ByVal bRevert As Long) As Integer

Private Declare Function RemoveMenu Lib "User32" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer

Private Declare Function DrawMenuBar Lib "User32" (ByVal hwnd As Integer) As Integer

Private Declare Function GetMenuItemCount Lib "User32" (ByVal hMenu As Integer) As Integer

Private Const MF_BYPOSITION = &H400&

Private Const MF_DISABLED = &H2&

Private Sub disableX(ByVal wnd As Form)

Dim hMenu As Integer, nCount As Integer

''得到系统Menu

hMenu = GetSystemMenu(wnd.Handle.ToInt32, 0)

''得到系统Menu的个数

nCount = GetMenuItemCount(hMenu)

''去除系统Menu

Call RemoveMenu(hMenu, nCount - 1, MF_BYPOSITION Or MF_DISABLED)

''重画MenuBar

DrawMenuBar(Me.Handle.ToInt32)

End Sub

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

''使用X不能用

disableX(Me)

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

''关闭窗口

Me.Close()

End Sub

''如果还要屏蔽Alt+F4,加上

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)

Dim SC_CLOSE As Integer = 61536

Dim WM_SYSCOMMAND As Integer = 274

''判断是系统消息,是不是关闭窗体,使Alt+F4无效

If m.Msg = WM_SYSCOMMAND AndAlso m.WParam.ToInt32 = SC_CLOSE Then

Exit Sub

End If

MyBase.WndProc(m)

End Sub

5、无标题栏的窗体的拖动问题

在特殊窗体的应用中,我们有时需要把窗体的标题栏屏蔽掉,以窗体换上自己的外壳。是,当去掉了窗体标题栏后,移动窗体就成了一个问题。

我们还是来看一下在VB6中的实现,VB6中实现(借助API函数SendMessage)

在设计时将窗体的BorderStyle属性设置为0-none

Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Any) As Long

Private Declare Sub ReleaseCapture Lib "User32" ()

Const WM_NCLBUTTONDOWN = &HA1

Const HTCAPTION = 2

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

Dim lngReturnValue As Long

If Button = 1 Then

''Release capture

Call ReleaseCapture()

''Send a ''left mouse button down on caption''-message to our form

lngReturnValue = SendMessage(Me.hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&)

End If

End Sub

Private Sub Form_Paint()

Me.Print("Click on the form, hold the mouse button and drag it")

End Sub

在VB.NET中,这次需要借助API SendMessage 了

在设计时将Form.FormBorderStyle 属性设置为None,然后添加以下代码:

Declare Function SendMessage Lib "user32" Alias "SendMess

网学推荐

免费论文

原创论文

浏览:
设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
湘ICP备09003080号