【发布时间】:2012-05-07 07:59:56
【问题描述】:
来自我添加的动态表单。我意识到我无法让 gif 动画在表单的背景中运行。所以我想通过在动态表单上嵌入一个图片框来尝试一下,但它不起作用,所以我在这里。
所以在我的主窗体 (Form1) 上,我有 2 个按钮、openfiledialog 和一个图片框。当您单击 button1 时,您会浏览要在图片框中显示的图像,当您按下 button2 时,您可以从下面的代码中看到。它将打开一个新表单,但我想要的是让图片框显示在整个表单上,而且还将我通过 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
任何帮助将不胜感激。
【问题讨论】:
-
你已经知道 BackgroundImage 没有动画。所以改为分配 WidgetBG.Image。
-
代码更新!现在我的问题是我无法移动每个无边界表单。你知道如何解决这个问题吗?
-
嗯,当然,它没有边框或标题栏。所以不要让它无边界。 stackoverflow.com/a/3102238/17034
-
对于这个特定的应用程序。我是故意让它有一个无边界的形式。我唯一的问题是移动它,因为我收到此错误“无法将'System.Windows.Forms.PictureBox'类型的对象转换为'System.Windows.Forms.Form'。”
标签: vb.net dynamic picturebox gif playback