使用不同内容打开相同的表单

时间:2014-11-12 16:32:29

标签: vb.net winforms

因此,我正在构建一个简单的Windows工具,以显示不同的嵌入视频和一些提示作为我公司特定部门的技术支持。问题是,我想要显示超过50个视频,并且我不想为每个视频创建一个表单。我的想法是拥有两个表单,一个是我有视频列表,然后点击所需的教程,它会打开一个新的表单,视频将在其中运行。所以我基本上在寻找一种方法来获取一个根据所选视频显示不同内容的表单。可能吗?这就是我现在为1个视频做的事情:

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim MyHTMLCode As String = "<object width=" & C() & "420" & C() & " height=" & C() & "315" & C() & " src=" & C() & "//www.youtube.com/embed/W7W8VjKIBUY" & C() & " frameborder=" & C() & "0" & C() & " allowfullscreen></object>"
    Me.WebBrowser1.DocumentText = MyHTMLCode
    Me.WebBrowser1.Update()

End Sub
Private Function C() As Object
    Return Convert.ToChar(34)

End Function

欢迎任何帮助。

此致

2 个答案:

答案 0 :(得分:0)

在表单中添加一个构造函数以接收URL:

    Dim f1 As New Form1("www.youtube.com/embed/W7W8VjKIBUY")
    f1.Show()

在Form1中:

Public Class Form1

    Private _URL As String

    Public Sub New(ByVal URL As String)
        Me.InitializeComponent()
        Me._URL = URL
    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim MyHTMLCode As String = "<object width=" & C() & "420" & C() & " height=" & C() & "315" & C() & " src=" & C() & "//" & Me._URL & C() & " frameborder=" & C() & "0" & C() & " allowfullscreen></object>"
        Me.WebBrowser1.DocumentText = MyHTMLCode
        Me.WebBrowser1.Update()
    End Sub

    Private Function C() As Object
        Return Convert.ToChar(34)
    End Function

End Class

答案 1 :(得分:0)

我通过向每个按钮/列表项添加操作以在webbrowser插件上导航,以一种简单的方式解决了我的问题。作品奇迹!谢谢大家的时间。请参阅下面的代码:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim form As New Form2
    form.Show()
    form.WebBrowser1.Navigate("http://www.youtube.com/embed/VeWYQPxzNZo")
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim form As New Form2
    form.Show()
    form.WebBrowser1.Navigate("http://www.youtube.com/embed/ghqVadag1-8")
End Sub