ピクチャボックスの擬似的な透明化
ピクチャボックスはフォームやプリンタ同様に文字列やグラフィックを自由に操作できます。
じゃ、下のオブジェクトを透かしてみたいですよね?
しかし、VBのピクチャボックスは背景色を透明にすることができません。そこで、背景の画像をピクチャボックスにコピーして擬似的に透明になってるかのようにしています。
サンプル(32bit) ダウンロード
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim strWork As String
Dim sngX As Single
Dim sngY As Single
If Button = vbLeftButton Then
With Picture1
'======[ ピクチャボックスの移動
'----[ 移動先座標算出
sngX = .Left + X - sngDownX
sngY = .Top + Y - sngDownY
'----[ 移動先補正
If sngX < 0 Then sngX = 0
If sngY < 0 Then sngY = 0
If (sngX + .Width) > Image1.Width Then sngX = Image1.Width - .Width
If (sngY + .Height) > Image1.Height Then sngY = Image1.Height - .Height
'----[ 移動
.Left = sngX
.Top = sngY
'======[ 背景のコピー
.PaintPicture Image1.Picture, 0, 0 _
, .ScaleWidth, .ScaleHeight _
, .Left + ((.Width - .ScaleWidth) / 2), .Top + ((.Height - .ScaleHeight) / 2) _
, .ScaleWidth, .ScaleHeight
'======[ 文字のセット
strWork = "擬似的に透明化してます"
.CurrentX = (.Width - .TextWidth(strWork)) / 2
.CurrentY = (.Height - .TextHeight(strWork)) / 2
Picture1.Print strWork
End With
End If
End Sub
サンプル解説
PaintPictureメソッドで下にある(サンプルの場合はImage1)画像のPicture1と重なってる部分だけをコピーして表示さています。
これでピクチャボックスが透明になったよーな見た目を得ることができます。
ただ、他のコントロールが重なっている場合までは考慮していませんのでご注意ください。
[ Window Close ]