摘要载入中… 请稍等…
内容载入中… 请稍等…
| ◎→ | 本类最新 |
|
VB6制作Win98风格的工具栏 动态加载ActiveX控件漫谈 实现窗口图像缩放、滚动技巧 VB中处理长列表框项的两种方法 VB应用程序中的工具提示和状态显 VB实现窗口的弹出式菜单 VB实现按钮浮动效果 |
|
| ◎→相关资源 | |
| C语言入门视频教程 C#编程WinForm入门视频 Asp.net入门视频教程下载 VC++编程视频教程下载 VB窗体文章 HTML入门教程 VB基础视频教程 VB窗体文章 VB文件文章 VB数据库文章 VB-API文章 VB控制文章 | |
| ◎→ | 热门资源 |
| 在VB中让控件大小和位置随着表单 制作方向按钮 制作半透明窗体和形状不规则的窗 制造出透明的Form 怎样得到文本框(TextBox)中的文 暂时禁止窗口更新 在最小化状态时提供提示 |
|
在VB中利用API实现窗体的平滑显示 Win98的一个新功能是窗体能够平滑显示,那我们是否能编程来实现这种功能呢?答案是肯定的。首先讲述一下原理,其实我并没有让窗体本身平滑地显示,而是在窗体显示之前在窗体的位置上画一系列的矩形,利用视觉暂留让人以为是窗体在从小变大。 下面就用VB来实现这种功能。 建立两个窗体form1和form2,在form1上添加如下控件:由五个optionbutton控件组成的控件数组,index为0-4,caption属性分别为“从中间扩散”、“右上到左下”、“左上到右下”、“右下到左上”和“左上到右下”,一个commandbutton,caption属性为“显示窗体”, 添加一个模块其中代码如下: Option Explicit `声明所用的API函数、常量和变量 Public Declare Function GetDC Lib “user32” (ByVal hwnd As Long) As Long Public Declare Function Rectangle Lib “gdi32” (ByVal hdc As Long, _ ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2_ As Long) As Long Public Declare Function SelectObject Lib “gdi32” (ByVal hdc As Long, _ ByVal hObject As Long) As Long Public Declare Function DeleteObject Lib “gdi32”(ByVal hObject As _ Long) As Long Public Declare Function ReleaseDC Lib “user32” (ByVal hwnd As Long,_ ByVal hdc As Long) As Long Public Declare Sub Sleep Lib “kernel32” (ByVal dwMilliseconds As Long) Public Declare Function CreateSolidBrush Lib “gdi32” (ByVal crColor As_ Long) As Long Public Declare Function GetBkColor Lib “gdi32” (ByVal hdc As Long) As Long Public hbrush As Long, hdc5 As Long Public dx As Long, dy As Long Public rx1 As Long, rx2 As Long, ry1 As Long, ry2 As Long Public i As Long, j As Long, bcolor As Long Public ind As Integer Public DispCnt As Long Public Sub showform(win As Form, ind) DispCnt = 60 `画几个矩形后显示窗体 `下面这段代码用来获得窗体颜色,不用me.backcolor的原因是窗体颜色不一定是系统调色板的颜色,如果用me.backcolor的话颜色可能会不准。 hdc5 = GetDC(0) bcolor = GetBkColor(win.hdc) hbrush = CreateSolidBrush(bcolor)`设定刷子颜色 Call SelectObject(hdc5, hbrush) dx = win.Width \ (DispCnt) dy = win.Height \ (DispCnt) j = 1 Select Case ind Case 1 dx = dx \ 2; dy = dy \ 2 For i = DispCnt To 1 Step -1 rx1 = (win.Left + dx * (i - 1)) \ Screen.TwipsPerPixelX ry1 = (win.Top + dy * (i - 1)) \ Screen.TwipsPerPixelY rx2 = rx1 + dx * 2 * j \ Screen.TwipsPerPixelX ry2 = rx1 + dy * 2 * j \ Screen.TwipsPerPixelY j = j + 1 Call Rectangle(hdc5, rx1, ry1, rx2, ry2) Sleep (1); Next i Case 2 For i = DispCnt To 1 Step -1 rx1 = (win.Left + win.Width - dx * j) \ Screen.TwipsPerPixelX ry1 = win.Top \ Screen.TwipsPerPixelY rx2 = (win.Left + win.Width) \ Screen.TwipsPerPixelX ry2 = (win.Top + dy * j) \ Screen.TwipsPerPixelY j = j + 1 Call Rectangle(hdc5, rx1, ry1, rx2, ry2) Sleep (1); Next i Case 3 For i = DispCnt To 1 Step -1 rx1 = win.Left \ Screen.TwipsPerPixelX ry1 = win.Top \ Screen.TwipsPerPixelY rx2 = rx1 + dx * j \ Screen.TwipsPerPixelX ry2 = rx1 + dy * j \ Screen.TwipsPerPixelY j = j + 1 Call Rectangle(hdc5, rx1, ry1, rx2, ry2) Sleep (1); Next i Case 4 For i = DispCnt To 1 Step -1 rx1 = (win.Left + dx * (i - 1)) \ Screen.TwipsPerPixelX ry1 = (win.Top + dy * (i - 1)) \ Screen.TwipsPerPixelY rx2 = (win.Left + win.Width) \ Screen.TwipsPerPixelX ry2 = (win.Top + win.Height) \ Screen.TwipsPerPixelY j = j + 1 Call Rectangle(hdc5, rx1, ry1, rx2, ry2) Sleep (1); Next i Case 5 For i = DispCnt To 1 Step -1 rx1 = (win.Left) \ Screen.TwipsPerPixelX ry1 = (win.Top + win.Height - dy * j) \ Screen.TwipsPerPixelY rx2 = (win.Left + dx * j) \ Screen.TwipsPerPixelX ry2 = (win.Top + win.Height) \ Screen.TwipsPerPixelY j = j + 1 Call Rectangle(hdc5, rx1, ry1, rx2, ry2) Sleep (1); Next i End Select Call ReleaseDC(0, hdc5)`释放设备描述表 Call DeleteObject(hbrush)`删除刷子 End Sub 在form1中输入如下代码 Private Sub Command1_Click()`显示窗体 Unload Form2 Load Form2 Form2.Show End Sub Private Sub Form_Load() ind = 1`初始化参数 End Sub Private Sub Option1_Click(Index As Integer) Select Case Index Case 0 ind = 1 Case 1 ind = 2 Case 2 ind = 3 Case 3 ind = 4 Case 4 ind = 5 Case 5 ind = 6 End Select End Sub 在form2中输入如下代码 Private Sub Form_Load() Call showform(Me, ind) End Sub 本程序调用了一些有关系统和绘图的API函数,有利于大家进一步了解API函数的功能。本程序在vb5企业版,Win98中运行通过。[1]
| 芯友网版权所有 1999-2006 | 著作权与商标声明 | 法律声明 | 服务条款 | 隐私声明 | 联系我们 |