In VS2005, The Component Container does not have a reference to the Form

I am trying to create a custom control that inherits from BindingSource. I need a reference to the containing form of this new control. From the BindingSource, I can use the .Container property to get the ComponentContainer, but there is no property or method to get a reference to the form from there.

Does anyone know how to get a reference to the form using Windows API

Thanks,




Answer this question

In VS2005, The Component Container does not have a reference to the Form

  • Christian Ratliff

    Hi,

    Could you please be more clear in your problem definition

    Thank you,
    Bhanu.



  • new to sql server

    what about the control's ".Parent" property (to get the container control) or the ".FindForm() " method to get the containing form

    an example from MSDN 2005 by Microsoft:

    // This example uses the Parent property and the Find method of Control to set
    // properties on the parent control of a Button and its Form. The example assumes
    // that a Button control named button1 is located within a GroupBox control. The 
    // example also assumes that the Click event of the Button control is connected to
    // the event handler method defined in the example.
    private void button1_Click(object sender, System.EventArgs e)
    {
      // Get the control the Button control is located in. In this case a GroupBox.
      Control control = button1.Parent;
      // Set the text and backcolor of the parent control.
      control.Text = "My Groupbox";
      control.BackColor = Color.Blue;
      // Get the form that the Button control is contained within.
      Form myForm = button1.FindForm();
      // Set the text and color of the form containing the Button.
      myForm.Text = "The Form of My Control";
      myForm.BackColor = Color.Red;
    }
    


  • iamshail

    Components are different than controls and don't have those properties and methods.

  • In VS2005, The Component Container does not have a reference to the Form