Reputation: 403
I'm trying to programmatically create a axWindowsMediaPlayer and show it:
private void button1_Click(object sender, EventArgs e)
{
AxWMPLib.AxWindowsMediaPlayer wmplayer = new AxWMPLib.AxWindowsMediaPlayer();
wmplayer.Size = new Size(200, 200);
wmplayer.enableContextMenu = false; //here it throws an exception
this.Controls.Add(wmplayer);
}
but it says {Property set of 'enableContextMenu' cannot be invoked at this time.}
why is that? why can I set Size but not enableContextMenu?
Upvotes: 1
Views: 738
Reputation: 403
I found the solution:
It is important that you do changes and/or function calls after you added wmplayer to this.Controls. I don't know why wmplayer.Size worked, but it is definitively the exception..
private void button1_Click(object sender, EventArgs e)
{
AxWMPLib.AxWindowsMediaPlayer wmplayer = new AxWMPLib.AxWindowsMediaPlayer();
this.Controls.Add(wmplayer);
wmplayer.Size = new Size(200, 200);
wmplayer.enableContextMenu = false; //here it throws an exception
}
works perfectly fine..
Upvotes: 2