Hi All,
I am doing one INTERESTING work with Context Menu Strip. I am
trying to insert a custom control / .Net control in Context menu as a
context menu strip. I tried inserting MonthCalender in Context Menu as
a context menu strip, it worked.
Now, i tried same with Windows Media Player ( a control available in
C#.Net). But I'm not able to set its URL property (i.e. path of the
media file). and i'm getting the exception like
System.Windows.Forms.AxHost+InvalidActiveXStateExc eption.
Those who are interested may read below extended information:
I have created one class named as Class2 i.e. Class2.cs file : Code
are as below
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using AxWMPLib;
using System.ComponentModel.Design.Serialization;
namespace ToolStripBaseRenderer
{
class Class2 : ToolStripControlHost
{
public Class2() : base(new AxWMPLib.AxWindowsMediaPlayer())
{ }
public AxWindowsMediaPlayer AxWPlayer
{
get
{
return Control as AxWindowsMediaPlayer;
}
}
public System.Drawing.Size WPlayerSize
{
get { return AxWPlayer.Size; }
set
{
AxWPlayer.Size = value;
}
}
public AxHost.State WPlayerAXHost
{
set
{
AxWPlayer.OcxState = value;
}
get
{
return AxWPlayer.OcxState;
}
}
public string WPlayerURL
{
get
{
return AxWPlayer.URL;
}
set
{
AxWPlayer.URL = value;
}
}
}
}
One windows form i.e. Form1.cs
Load event of Form1 is as below:
private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
private void Form1_Load(object sender, EventArgs e)
{
Class2 cls2 = new Class2();
cls2.WPlayerSize = new System.Drawing.Size(237, 180);
string fpath = "C:\\a.wmv";
cls2.WPlayerURL = fpath;
contextMenuStrip1.Items.Add(cls2);
}
Now in above code i'm getting an exception while assigning 'fpath'
value to URL of windows media player
i.e. at statement cls2.WPlayerURL = fpath;
Exception is like "System.Windows.Forms.AxHost
+InvalidActiveXStateException".
If i set OcxState property (i.e here it is WPlayerAXHost in Class2.cs
file) of windows media player from Form1_Load event than it may solve
problem ....but the issue is i' dont know exactly WHY i need to set
that property and how to set that property....
If ne body have ne solution plz help me out.....if above data is not
enough to understand i can send the whole project...but plz help me....