locked
Component on a Form or UserCOntrol RRS feed

  • Question

  • hi,
    the problem i have is:
    i made an Component and i dragged on this component for example two textboxes and compile it.

    now i want to crate a form or usercontrol and drag the self made component on the form or usercontrol,
    this all works fine, but i want be able to see the component textboxes on the form, so i can change fr example the position  or somthing like that.
    and it is neccesary that this should be from a component and not from a UserControl.
    Friday, August 24, 2007 12:56 PM

Answers

  • Using a UserControl would trivially solve your problem.  If you insist on using a Component, you'll have to add the controls to the form yourself.  Make sure the Modifier property on the controls is set to Public, then use code like this in the form:

        public Form1() {
          InitializeComponent();
          TextBox box = component11.textBox1;
          box.Location = new Point(10, 5);
          this.Controls.Add(box);
          box = component11.textBox2;
          box.Location = new Point(10, 30);
          this.Controls.Add(box);
        }
    Saturday, August 25, 2007 5:02 PM

All replies

  • If you want to still be able to change properties of a control contained inside a component then you need the component to expose either the control itself as a public property (in which case the user of the component will be able to change everything about the control) or just the properties of the controls you want the user of the component to be able to change as public properties on the component.

    Friday, August 24, 2007 3:21 PM
  • yes, but this should be done in the designer.
    Friday, August 24, 2007 3:27 PM
  •  Coke-22 wrote:
    yes, but this should be done in the designer.

     

    if you set the control as public in the component, it will be visible in the designer as a property of the component. What's the problem?

    Friday, August 24, 2007 3:33 PM
  • i tried this but cant see anything on the form, if i drag the component on te form it only appears in the notvisible components taskbar.
    (also recomiled it)

    the component have nonvisual controls and visual controls and the aim was to se the visual controls on form.


    Friday, August 24, 2007 3:45 PM
  • Using a UserControl would trivially solve your problem.  If you insist on using a Component, you'll have to add the controls to the form yourself.  Make sure the Modifier property on the controls is set to Public, then use code like this in the form:

        public Form1() {
          InitializeComponent();
          TextBox box = component11.textBox1;
          box.Location = new Point(10, 5);
          this.Controls.Add(box);
          box = component11.textBox2;
          box.Location = new Point(10, 30);
          this.Controls.Add(box);
        }
    Saturday, August 25, 2007 5:02 PM