1.新しいプロジェクトを作り、Class1とForm1を用意します。 2.Class1には以下のコードを書き入れます '-------Class1 Option Explicit Public csControl As Control Public csLeft As Double Public csTop As Double Public csWidth As Double Public csHeight As Double Public csFontSize As Double
Private Clipped As Boolean Private ctls As Collection Private clpScaleWidth As Double Private clpScaleHeight As Double
Private Sub Form_Load() Call ClipControl End Sub
Private Function ClipControl() 'コントロールの現在の状態をクリップする Dim ctl As Control Dim ctlst As Class1
On Error Resume Next
Set ctls = New Collection clpScaleWidth = Me.ScaleWidth clpScaleHeight = Me.ScaleHeight For Each ctl In Me.Controls Set ctlst = New Class1 With ctlst Set .csControl = ctl .csLeft = ctl.Left .csTop = ctl.Top .csWidth = ctl.Width .csHeight = ctl.Height .csFontSize = ctl.FontSize End With Call ctls.Add(ctlst) Next Clipped = True End Function
Private Sub Form_Resize() 'クリップしたコントロールをリサイズする Dim ctlst As Class1 Dim ratScaleWidth As Double Dim ratScaleHeight As Double
If Clipped Then On Error Resume Next '水平、垂直方向の拡大率を決定する ratScaleWidth = Me.ScaleWidth / clpScaleWidth ratScaleHeight = Me.ScaleHeight / clpScaleHeight 'それぞれのコントロールを拡大する For Each ctlst In ctls With ctlst .csControl.Top = .csTop * ratScaleHeight .csControl.Left = .csLeft * ratScaleWidth .csControl.Width = .csWidth * ratScaleWidth .csControl.Height = .csHeight * ratScaleHeight .csControl.FontSize = .csFontSize * ratScaleWidth 'フォントサイズの拡大幅は適当です End With Next End If End Sub
'-------Class1 Option Explicit Public csControl As Control Public csHideSSTab As Boolean Public csLeft As Double Public csTop As Double Public csWidth As Double Public csHeight As Double Public csFontSize As Double
'-------Form1 Option Explicit Private Clipped As Boolean Private ctls As Collection Private clpScaleWidth As Double Private clpScaleHeight As Double
Private Function ClipControl() 'コントロールの現在の状態をクリップする Dim ctl As Control Dim ctlst As Class1
Set ctls = New Collection clpScaleWidth = Me.ScaleWidth clpScaleHeight = Me.ScaleHeight For Each ctl In Me.Controls Set ctlst = New Class1 With ctlst Set .csControl = ctl If (TypeOf ctl.Container Is SSTab) And (ctl.Left < 0) Then .csHideSSTab = True .csLeft = ctl.Left + 75000 Else .csHideSSTab = False .csLeft = ctl.Left End If .csTop = ctl.Top .csWidth = ctl.Width .csHeight = ctl.Height On Error Resume Next .csFontSize = ctl.FontSize On Error GoTo 0 End With Call ctls.Add(ctlst) Next Clipped = True End Function
Private Sub Form_Load() Call ClipControl End Sub
Private Sub Form_Resize() 'クリップしたコントロールをリサイズする Dim ctlst As Class1 Dim ratScaleWidth As Double Dim ratScaleHeight As Double
If Clipped Then On Error Resume Next '水平、垂直方向の拡大率を決定する ratScaleWidth = Me.ScaleWidth / clpScaleWidth ratScaleHeight = Me.ScaleHeight / clpScaleHeight 'それぞれのコントロールを拡大する For Each ctlst In ctls With ctlst If .csHideSSTab Then .csControl.Left = .csLeft * ratScaleWidth - 75000 Else .csControl.Left = .csLeft * ratScaleWidth End If .csControl.Top = .csTop * ratScaleHeight .csControl.Width = .csWidth * ratScaleWidth .csControl.Height = .csHeight * ratScaleHeight .csControl.FontSize = .csFontSize * ratScaleWidth 'フォントサイズの拡大幅は適当です End With Next End If End Sub