追加した動的フォームから。フォームのバックグラウンドでgifアニメーションを実行できないことに気づきました。ダイナミックフォームにピクチャーボックスを埋め込んでみようと思ったのですが、うまくいかないのでここにいます。
したがって、メインフォーム(Form1)には、2つのボタン、openfiledialog、およびpictureboxがあります。ボタン1をクリックすると、画像ボックスに表示する画像を参照し、ボタン2を押すと、以下のコードからわかります。新しいフォームが開きますが、フォーム全体にピクチャーボックスを表示するだけでなく、メインフォームからForm1を介して選択したgifアニメーションを、動的に埋め込まれたフォームで、ピクチャーボックスで再生することも必要です。今はBackgroundImageとして使用できないので、単なる画像として使用していますが、問題は、各フチなしフォームを移動できず、それぞれを閉じることができないことです。
とにかくここに私のコードがあります。
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
WidgetForm = New Form()
WidgetForm.ShowInTaskbar = False
WidgetForm.TopMost = True
WidgetForm.FormBorderStyle = Windows.Forms.FormBorderStyle.None
WidgetForm.ContextMenuStrip = ContextMenuStrip2
WidgetForm.Show()
Dim WidgetBG As PictureBox = New PictureBox()
sizew = Me.TextBox1.Text
sizey = Me.TextBox2.Text
WidgetBG.Size = New System.Drawing.Size(sizew, sizey)
WidgetBG.Image = Image.FromFile(Me.OpenFileDialog1.FileName)
WidgetBG.Location = New System.Drawing.Point(0, 0)
WidgetBG.Visible = True
WidgetForm.Controls.Add(WidgetBG)
opac = Me.TextBox3.Text
WidgetForm.Opacity = opac
WidgetForm.Size = New System.Drawing.Size(sizew, sizey)
'Add the event here
AddHandler WidgetBG.MouseDown, AddressOf WidgetBG_MouseDown
AddHandler WidgetBG.MouseMove, AddressOf WidgetBG_MouseMove
AddHandler WidgetBG.MouseUp, AddressOf WidgetBG_MouseUp
AddHandler WidgetBG.DoubleClick, AddressOf WidgetBG_DoubleClick
End Sub
Private Sub WidgetBG_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
If e.Button = Windows.Forms.MouseButtons.Left Then
drag = True
mousex = Windows.Forms.Cursor.Position.X - CType(sender, Form).Left
mousey = Windows.Forms.Cursor.Position.Y - CType(sender, Form).Top
End If
Timer1.Enabled = True
Timer1.Interval = 2500
End Sub
Private Sub WidgetBG_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
If drag Then
CType(sender, Form).Top = Windows.Forms.Cursor.Position.Y - mousey
CType(sender, Form).Left = Windows.Forms.Cursor.Position.X - mousex
End If
End Sub
Private Sub WidgetBG_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Timer1.Enabled = False
drag = False
End Sub
Private Sub WidgetBG_DoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
CType(sender, Form).Close()
End Sub
どんな助けでも大歓迎です。