開発環境:
Windows10 Pro
Visual Studio Community 2019
開発言語:
VB.NET FrameWork4.7.2
>
背景を透過にしたFormに画像を表示する。で、画像のみを表示するFormの考え方を示しましたが、
思ったよりも反応があり、XXXの場合どうなるか?など、問い合わせがありました。
たいがいは自分でやってみて!と返すのですが、「画像と入力ボックスを同時に表示したい。」というのが複数ありましたので、対応してみました。
下記のようなFormを用意します。
Formに下記コーディングをします。
Imports System.Reflection.MethodBase Friend Class FomGAZO Inherits System.Windows.Forms.Form Private mousePoint As Point Private Sub FomGAZO_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs ) Handles MyBase.MouseDown If (e.Button And MouseButtons.Left) = MouseButtons.Left Then '位置を記憶する mousePoint = New Point(e.X, e.Y) End If End Sub Private Sub FomGAZO_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs ) Handles MyBase.MouseMove If (e.Button And MouseButtons.Left) = MouseButtons.Left Then Me.Left += e.X - mousePoint.X Me.Top += e.Y - mousePoint.Y End If End Sub 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 FomGAZO_Load(sender As Object, e As EventArgs ) Handles MyBase.Load Try Me.Text = "画像フォーム" 'imText1.Visible = False 'Com_Cancel.Visible = False Com_Cancel.BackColor = Color.White GroupBox1.BackColor = Color.Transparent GroupBox1.FlatStyle = FlatStyle.Flat 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 End Class
実行結果です
画像部分の入力部の枠がかぶっていないところでドラック出来ます。
入力部の透明なところと画像にかぶっていところでは、何のイベントも発生しません。
TextBoxやボタンは有効ですので、通常と変わらず使用できます。
デザイン的な変以外では、あまり意味は無いように思いますが、できることはできます。