locked
Is it possible to specify access modifier in IDesignerHost.CreateComponent? RRS feed

  • Question

  • Hi all,

    I'm working on a control that generate/destroy/manipulate other controls on the form. I can preserve the name and other stuff using the designerhost:

    IDesignerHost host = GetService(typeof(IDesignerHost)) as IDesignerHost;
    if (host!=null)
       TextBox textbox = (TextBox)host.CreateComponent(typeof(TextBox));


    IDesignerHost.CreateComponent is overloaded with a second parameter to specify the name of the component I am creating, but I can't find any way how to specify the access modifier to the CreateComponent method.

    So my question is, is it possible to specify access modifier on the CreateComponent or is there any other way to achieve what I want to do?

    For example, I want to generate a TextBox with a name "UserLine" and "protected" as its modifier. I'm using Visual Studio 2003 for this project.

    Thanks in advance,

    -chris

    Friday, November 4, 2005 8:58 AM

Answers

  • I already solved this with a workaround.

    -chris

    Tuesday, November 8, 2005 3:33 AM

All replies

  • I already solved this with a workaround.

    -chris

    Tuesday, November 8, 2005 3:33 AM
  • Big Smile Could you share your solution with us? (or me?).

    Thank You in advance Chris!
    Tuesday, November 8, 2005 3:19 PM
  • Had a similar problem and one of my friend had a neat little solution

    Try

     IComponent cp = this.designerHost.CreateComponent(typeof(IDesignerHost));
                PropertyDescriptor pd = TypeDescriptor.GetProperties(cp)["Modifiers"];
                pd.SetValue(cp, System.CodeDom.MemberAttributes.Family);

    System.CodeDom.MemberAttributes.Family = Protected :)



    • Edited by Chanakasat Monday, February 9, 2015 10:30 AM
    Monday, February 9, 2015 10:28 AM