2017-10-05 72 views
0

我爲我製作了一個媒體播放器,我需要一個覆蓋層,它的唯一工作方式是創建一個放置在頂部的表單,我使用計時器來放置位置表單位於媒體元素左上角的位置,並顯示主表單何時移動。有什麼方法可以綁定覆蓋表單的位置嗎?在其他地方包括位置的頂部綁定表

這是從計時器代碼:

Private Sub TimerOverlay_Tick(sender As Object, e As EventArgs) Handles TimerOverlay.Tick 
    If OrgPoint <> MediaPlayer.PointToScreen(Point.Empty) Then 
     FrmOverlay.Location = MediaPlayer.PointToScreen(Point.Empty) 
     OrgPoint = MediaPlayer.PointToScreen(Point.Empty) 
    End If 
End Sub 

這是形式:

'LabelMain' 

    Me.LabelMain.BorderColor = System.Drawing.Color.FromArgb(CType(CType(5, Byte), Integer), CType(CType(5, Byte), Integer), CType(CType(5, Byte), Integer)) 
    Me.LabelMain.Dock = System.Windows.Forms.DockStyle.Fill 
    Me.LabelMain.Font = New System.Drawing.Font("Arial", 30.0!, System.Drawing.FontStyle.Bold) 
    Me.LabelMain.ForeColor = System.Drawing.Color.White 
    Me.LabelMain.Location = New System.Drawing.Point(0, 0) 
    Me.LabelMain.Name = "LabelMain" 
    Me.LabelMain.Size = New System.Drawing.Size(720, 104) 
    Me.LabelMain.TabIndex = 0 

    'FrmOverlay' 

    Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) 
    Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font 
    Me.BackColor = System.Drawing.Color.Black 
    Me.ClientSize = New System.Drawing.Size(720, 104) 
    Me.Controls.Add(Me.LabelMain) 
    Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None 
    Me.Name = "FrmOverlay" 
    Me.Opacity = 0.8R 
    Me.ShowIcon = False 
    Me.ShowInTaskbar = False 
    Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen 
    Me.TransparencyKey = System.Drawing.Color.Black 
+0

你能分享一些相關的代碼片段嗎? – gareththegeek

+0

@gareththegeek我編輯了帖子,我擁有的一切。我使用的媒體播放器是使用vlc dotnet的vlc:https://github.com/ZeBobo5/Vlc.DotNet – PeterJ

回答

1

不太清楚什麼是你的意圖。你要轉另一個之上一種形式?然後同步運動和尺寸的變化?基本上,您可以將處理程序添加到父窗體的SizeChanged和LocationChanged事件。但那不是它的結束..這似乎工作:

public partial class SomeForm : Form 
{ 
    Form overlay; 

    public SomeForm() 
    { 
     InitializeComponent(); 

     this.overlay = new Form(); 
     overlay.Owner = this; 
     overlay.StartPosition = FormStartPosition.Manual; 
     overlay.FormBorderStyle = FormBorderStyle.None; 
     overlay.BackColor = Color.Blue; 

     this.LocationChanged += SomeForm_LocationChanged; 
     this.SizeChanged += SomeForm_SizeChanged; 
     this.FormClosed += SomeForm_FormClosed; 
     this.Load += SomeForm_Load; 
    } 

    private void SomeForm_Load(object sender, EventArgs e) 
    { 
     overlay.Size = this.ClientSize; 
     overlay.Location = this.PointToScreen(new Point(0, 0)); 
     overlay.Show(); 
    } 

    private void SomeForm_FormClosed(object sender, FormClosedEventArgs e) 
    { 
     overlay.Close(); 
    } 

    private void SomeForm_SizeChanged(object sender, EventArgs e) 
    { 
     overlay.Size = this.ClientSize; 
    } 

    private void SomeForm_LocationChanged(object sender, EventArgs e) 
    { 
     overlay.Location = this.PointToScreen(new Point(0,0)); 
    } 
} 
+0

我是一個白癡......這很簡單我不知道爲什麼我認爲它很複雜或爲什麼我忘記了LocationChanged事件。謝謝! – PeterJ