Control の透過度を設定する (SetLayeredWindowAttributes)
user32.dll の SetLayeredWindowAttributes 等を用いて、Control の透過度を設定します。
サンプルのダウンロード
■サンプルの説明

透過度の NumericUpDown の値を小さくして、透過度変更 ボタンを押下すると、Form が半透明になります。
■コード
F0003_SetLayeredWindowAttributes.vb
Imports System.Runtime.InteropServices ''' <summary> ''' SetLayeredWindowAttributes(user32.dll) ''' </summary> Partial Public Class F0003_SetLayeredWindowAttributes ''' <summary> ''' SetLayeredWindowAttributes(ウィンドウの透過度の設定)の宣言 ''' </summary> <DllImport("user32.dll", CharSet:=CharSet.Auto)> _ Private Shared Function SetLayeredWindowAttributes( _ ByVal hWnd As IntPtr, _ ByVal crKey As Integer, _ ByVal Alpha As Byte, _ ByVal dwFlags As Integer) _ As Boolean End Function ''' <summary> ''' SetWindowLong(ウィンドウ情報の設定)の宣言 ''' </summary> <DllImport("user32.dll", CharSet:=CharSet.Auto)> _ Private Shared Function SetWindowLong( _ ByVal hWnd As IntPtr, _ ByVal nIndex As Integer, _ ByVal dwNewLong As Integer) _ As Integer End Function ''' <summary> ''' GetWindowLong(ウィンドウ情報の取得)の宣言 ''' </summary> <DllImport("user32.dll", CharSet:=CharSet.Auto)> _ Private Shared Function GetWindowLong( _ ByVal hWnd As IntPtr, _ ByVal nIndex As Integer) _ As Integer End Function '拡張ウィンドウスタイル Private Const GWL_EXSTYLE As Integer = -20 '透過属性 Private Const WS_EX_LAYERED As Integer = &H80000 '指定色の透明化(crKeyを使用する場合) Private Const LWA_COLORKEY As Integer = 1 '指定色の透明化(bAlphaを使用する場合) Private Const LWA_ALPHA As Integer = 2 ''' <summary> ''' ロード時のイベント ''' </summary> Private Sub F0003_SetLayeredWindowAttributes_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Me.Text = "F0003_SetLayeredWindowAttributes" Me.Label1.Text = "透過度" Me.NumericUpDown1.Maximum = 255 Me.NumericUpDown1.Value = 255 Me.Button1.Text = "透過度変更" End Sub ''' <summary> ''' 透過度変更ボタンクリック時のイベント ''' </summary> Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim hWnd As IntPtr Dim alpha As Byte hWnd = Me.Handle alpha = Byte.Parse(Me.NumericUpDown1.Value.ToString()) '現在の拡張属性を取得 Dim hInfo As Integer = GetWindowLong(hWnd, GWL_EXSTYLE) '現在の拡張属性に透過属性を追加 hInfo = hInfo Or WS_EX_LAYERED SetWindowLong(hWnd, GWL_EXSTYLE, hInfo) '半透明化 Dim returnValue As Boolean = SetLayeredWindowAttributes( _ hWnd, _ 0, _ alpha, _ LWA_ALPHA) End Sub End Class