如何把小图片填满 MDIForm 成为背景图?
以下这个范例,要:
1、一个 MDIForm:不必设定任何属性。
2、一个 Form1:不一定是 MDIChild,最好 MDIChild 为 False,但是 AutoRedraw 设成 True。
3、Form1 上面放一个隐藏的 PictureBox:名称为 Picture1,不必设定 Picture 属性。
4、一张图片的完整路径。
’将以下模组放入 MDIForm 的声明区中: Sub TileMDIBkgd(MDIForm As Form, bkgdtiler As Form, bkgdfile As String) If bkgdfile = "" Then Exit Sub Dim ScWidth%, ScHeight% ScWidth% = Screen.Width / Screen.TwipsPerPixelX ScHeight% = Screen.Height / Screen.TwipsPerPixelY Load bkgdtiler bkgdtiler.Height = Screen.Height bkgdtiler.Width = Screen.Width bkgdtiler.ScaleMode = 3 bkgdtiler!Picture1.Top = 0 bkgdtiler!Picture1.Left = 0 bkgdtiler!Picture1.Picture = LoadPicture(bkgdfile) bkgdtiler!Picture1.ScaleMode = 3 For n% = 0 To ScHeight% Step bkgdtiler!Picture1.ScaleHeight For o% = 0 To ScWidth% Step bkgdtiler!Picture1.ScaleWidth bkgdtiler.PaintPicture bkgdtiler!Picture1.Picture, o%, n% Next o% Next n% MDIForm.Picture = bkgdtiler.Image Unload bkgdtiler End Sub |
Private Sub MDIForm_Load() TileMDIBkgd Me, Form1, "c:\windows\Tiles.bmp" End Sub |
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Public Const WM_CLOSE = &H10 |
Dim winHwnd As Long Dim RetVal As Long winHwnd = FindWindow(vbNullString, "小算盘") Debug.Print winHwnd If winHwnd <> 0 Then RetVal = PostMessage(winHwnd, WM_CLOSE, 0&, 0&) If RetVal = 0 Then MsgBox "Error posting message." End If Else MsgBox "并未开启小算盘程序." End If |
True:显示鼠标 / False:隐藏鼠标 Declare Function ShowCursor Lib "user32" Alias "ShowCursor" (ByVal bShow As Long) As Long |
’在声明区中 (Bas Module / Form Module) 加入以下声明: Public Const EWX_LOGOFF = 0 ’这四个常数值可以并用 Public Const EWX_SHUTDOWN = 1 Public Const EWX_REBOOT = 2 Public Const EWX_FORCE = 4 Declare Function ExitWindowsEx Lib "user32" Alias "ExitWindowsEx" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long ’实例:如果您想强迫关机重开机,程序码如下: ret = ExitWindowsEx(EWX_FORCE OR EWX_REBOOT, 0) |
Dim RetVal As Long RetVal = Shell("C:\Windows\Notepad.exe C:\Test.txt", 3) ’3代表视窗会最大化,并具有驻点,细节请查 Help |
’在声明区中加入以下声明: Const MAX_PATH = 260 Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long Public Function GetWinPath() Dim strFolder As String Dim lngResult As Long strFolder = String(MAX_PATH, 0) lngResult = GetWindowsDirectory(strFolder, MAX_PATH) If lngResult <> 0 Then GetWinPath = Left(strFolder, InStr(strFolder, Chr(0)) - 1) Else GetWinPath = "" End If End Function ’在程序中使用方法如下: Private Sub Command1_Click() Call MsgBox("您电脑中 Windows 目录的正确路径是: " & GetWinPath, vbInformation) End Sub |
VB部分相关文章推荐:
摘自:网络整理
相关文章参考:
★VB取得TextBox、RichTextBox光标所在的行和列(支持汉字)
★VB取得TextBox、RichTextBox光标所在的行和列(支持汉字)
★VB根据窗体自动调整窗体内控件大小 注:实用,可以直接引用
★Visual Basic编程常见问题及解答(1)
★Visual Basic编程常见问题及解答(2)
★Visual Basic编程常见问题及解答(3)
★VisualBasic变量、常数和数据类型及过程概述
★VB6的后期绑定和前期绑定
★VB 计算自己程序段所用时间
★VB 获取路径名各部分 (获取文件路径,获取文件名,获取文件扩展名)自编
★VB 在浏览器中打开指定网址
评论