開発環境:
Windows10 Pro
Microsoft Visual Studio Community 2019
開発言語:
VB.NET FrameWork4.7.2
ディスクトップアプリで背景を透過にしたFormの背景画像にこれまた透過部分のある画像を読み込むとどうなるか試してみました。
まず、下記のようなフォームを準備しておきます。
フォームに下記コーディングをします。
Imports System.Reflection.MethodBase Friend Class FomGAZO Inherits System.Windows.Forms.Form Private Sub Com_Cancel_Click(ByVal eventSender As System.Object, _ ByVal eventArgs As System.EventArgs) _ Handles Com_Cancel.Click Me.Close() End Sub Private Sub frmTOKUI_FUKA_Load(sender As Object, e As EventArgs) _ Handles MyBase.Load Try Me.Text = "画像フォーム" imText1.Visible = False Com_Cancel.Visible = False Me.FormBorderStyle = FormBorderStyle.None Me.TransparencyKey = Me.BackColor Me.BackgroundImageLayout = ImageLayout.Zoom Dim url As String = ".\o0522052914887066710.png" Dim wc As New System.Net.WebClient() Dim stream As System.IO.Stream = wc.OpenRead(url) Dim bitmap As Bitmap = New Bitmap(stream) stream.Close() ' 画像の背景を透明にする bitmap.MakeTransparent() Me.BackgroundImage = bitmap Catch ex As Exception MessageBox.Show(GetCurrentMethod.Name & vbCrLf & ex.Message) End Try End Sub Private Sub imText1_TextChanged(sender As Object, e As EventArgs) _ Handles imText1.TextChanged RemoveHandler imText1.TextChanged, AddressOf imText1_TextChanged End Sub Private Sub frmTOKUI_FUKA_Click(sender As Object, e As EventArgs) _ Handles Me.Click Try imText1.Visible = True Com_Cancel.Visible = True Me.FormBorderStyle = FormBorderStyle.FixedDialog Me.TransparencyKey = Nothing Me.BackgroundImage = Nothing Catch ex As Exception End Try End Sub End Class
起動すると画像部分だけが表示されます。
画像をClickすると、通常のフォームに変わります。
コードはシンプルなので、説明は省きます。