In C # Windows.Forms, I want to intercept the paste-windowmessage parameter for combobox. Since this does not work, overriding the WndProc method for combobox because I need to override the WndProc text field inside the combobox, I decided to create a custom class like NativeWindow that overrides WndProc. I assign a descriptor and release it when the combobox descriptor is destroyed. But when Dispose for combobox is called a problem, I get an InvalidOperationException saying that an invalid cross-stream operation has occurred, and that the combobox was accessible from a stream other than the stream in which it was created. Any ideas what is going wrong here?
Below you will see what my classes look like:
public class MyCustomComboBox : ComboBox
{
private WinHook hook = null;
public MyCustomComboBox()
: base()
{
this.hook = new WinHook(this);
}
private class WinHook : NativeWindow
{
public WinHook(MyCustomComboBox parent)
{
parent.HandleCreated += new EventHandler(this.Parent_HandleCreated);
parent.HandleDestroyed += new EventHandler(this.Parent_HandleDestroyed);
}
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
}
private void Parent_HandleCreated(object sender, EventArgs e)
{
MyCustomComboBox cbx = (MyCustomComboBox)sender;
this.AssignHandle(cbx.Handle);
}
private void Parent_HandleDestroyed(object sender, EventArgs e)
{
this.ReleaseHandle();
}
}
}