locked
Visual Studio SDK: Error Cannot implicitly convert type ‘…MyUserControl' to 'System.Windows.Forms.IWin32Window' RRS feed

  • Question

  • I am creating a Visual Studio options page exactly as described in the example - Walkthrough: Creating an Options Page located at http://msdn.microsoft.com/en-us/library/bb166195.aspx- I am receiving the following error - Cannot implicitly convert type '...MyUserControl' to 'System.Windows.Forms.IWin32Window'' as I return the usercontrol page to IWin32Window for the following code:

    [Browsable(false)]
    [DesignerSerializationVisibility(
    	DesignerSerializationVisibility.Hidden)]
    protected override IWin32Window Window
    {
    	get
            {
            	MyUserControl page = new MyUserControl();
                    page.optionsPage = this;
                    page.Initialize();               
                    return page;
            }            
    }

    I tried explicit conversion and received and an invalid cast exception. The platform is Windows 8.1 and Visual Studios 2013 update 2.




    • Edited by innovoCAD Wednesday, July 9, 2014 10:52 AM
    Wednesday, July 9, 2014 10:49 AM

Answers

  • Make sure your MyUserControl inherits UserControl 

    public partial class MyUserControl : UserControl

    • Marked as answer by Anna Cc Thursday, July 17, 2014 1:49 AM
    Wednesday, July 9, 2014 10:57 AM
  • Hi,

    It works fine for me.

    Please make sure that you add an override for the OptionPageCustom.Window property to the OptionPageCustom class to create, initialize, and return an instance of MyUserControl in the package code file.

    I paste some code for your reference.

    MyUserControl.cs

    public partial class MyUserControl : UserControl
        {
            public MyUserControl()
            {
                InitializeComponent();
            }
    
            internal OptionPageCustom optionsPage;
    
            public void Initialize()
            {
                textBox1.Text = optionsPage.OptionString;
            }
    
            //private void textBox1_MouseLeave(object sender, EventArgs e)
            //{
            //    optionsPage.OptionString = textBox1.Text;
            //}
            private void textBox1_Leave(object sender, EventArgs e)
            {
                optionsPage.OptionString = textBox1.Text;
            }
    
        }

    Best regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    • Edited by Anna Cc Thursday, July 10, 2014 7:00 AM
    • Marked as answer by Anna Cc Thursday, July 17, 2014 1:48 AM
    Thursday, July 10, 2014 6:55 AM

All replies

  • Make sure your MyUserControl inherits UserControl 

    public partial class MyUserControl : UserControl

    • Marked as answer by Anna Cc Thursday, July 17, 2014 1:49 AM
    Wednesday, July 9, 2014 10:57 AM
  • Hi,

    It works fine for me.

    Please make sure that you add an override for the OptionPageCustom.Window property to the OptionPageCustom class to create, initialize, and return an instance of MyUserControl in the package code file.

    I paste some code for your reference.

    MyUserControl.cs

    public partial class MyUserControl : UserControl
        {
            public MyUserControl()
            {
                InitializeComponent();
            }
    
            internal OptionPageCustom optionsPage;
    
            public void Initialize()
            {
                textBox1.Text = optionsPage.OptionString;
            }
    
            //private void textBox1_MouseLeave(object sender, EventArgs e)
            //{
            //    optionsPage.OptionString = textBox1.Text;
            //}
            private void textBox1_Leave(object sender, EventArgs e)
            {
                optionsPage.OptionString = textBox1.Text;
            }
    
        }

    Best regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    • Edited by Anna Cc Thursday, July 10, 2014 7:00 AM
    • Marked as answer by Anna Cc Thursday, July 17, 2014 1:48 AM
    Thursday, July 10, 2014 6:55 AM