动态裁剪窗体标题栏

本文演示了如何利用API进行窗体标题栏的裁剪和恢复,一并演示了控件的动态添加方法:

 

'This sample show you how to cut the caption title exactly and create controls with code.
'add a new form ,do nothing but copy this codes for it.
Option Explicit
    Private Declare Function CreateRectRgn Lib "gdi32" (ByVal x1 As Long, ByVal y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
    Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
    Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long

  Private WithEvents cmd1 As CommandButton
  Private WithEvents cmd2 As CommandButton
Private Sub cmd1_Click() '******************
Dim capheight As Long, area As Long
   Me.ScaleMode = 2
   Me.ForeColor = vbRed
   Me.Line (1, 0)-(Me.Width, 0) '紧贴标题栏画线做标记
   capheight = GetSystemMetrics(33) + GetSystemMetrics(4) ' 边框宽度+标题栏高度
   area = CreateRectRgn(0, capheight, Me.Width, Me.Height) '画无标题栏的矩形框
   area = SetWindowRgn(Me.hWnd, area, True) '裁剪标题栏
End Sub
Private Sub cmd2_Click() '*******************
Me.ScaleMode = 2
Dim area As Long
area = CreateRectRgn(0, 0, Me.Width, Me.Height) '画含标题栏的矩形框
area = SetWindowRgn(Me.hWnd, area, True) '恢复标题栏
End Sub
Private Sub Form_Load()
Me.WindowState = 0
Me.Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2, 8000, 5000'居中及设置窗体大小
  Set cmd1 = Controls.Add("VB.CommandButton", "cmd1", Me)'添加cmd1按纽
  Set cmd2 = Controls.Add("VB.CommandButton", "cmd2", Me)'添加cmd2按纽
  cmd1.Move 1000, 1000, 1500, 500
  cmd2.Move 3000, 1000, 1500, 500
  cmd1.Caption = "裁剪标题栏"
  cmd2.Caption = "恢复标题栏"
  cmd1.Visible = True
  cmd2.Visible = True
End Sub

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值