CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1
  1. #1
    Join Date
    Jul 2008
    Posts
    29

    Weird: Control does not appear in container control.

    Using: Visual Studio 2008, Framework 3.5.

    I tried creating a control that contains a textbox and a label and then resize itself to fit these things. I then tried to add this to a control whose parent is the form.

    public TestTopControl(TestTopControlSettings sis)
    {
    this.ModelChaned +=new ViewDelegates.ModelChangedEventHandler(UseNewData);
    this.Name = "Testname";
    this.Location = new Point(sis.XLocation, sis.YLocation);
    this.PropertyName = sis.Target;
    this.Size = new Size(300, 300);
    testComboBox = new TestComboBox();
    testComboBox.Location = new Point(50, 50);
    this.Controls.Add(testComboBox);
    TestInput1 = new FloatInput(100, 100, "Test", "Test: This works.", 50);
    TestInput2 = new StringInput(100, 130, "Test", "This should work aswell", 50);
    this.Controls.Add(TestInput2);
    this.Controls.Add(TestInput1);

    testComboBox.SelectedIndexChanged += new EventHandler(testComboBox_SelectedIndexChanged);
    Application.Idle += new EventHandler(Application_Idle);
    }

    this generates output according to works.jpg in attached files. If I just change the order in which the controls are added to TestTopControl it generates output according to works1.jpg. Am I missing something basic here? Here is the code for the baseclass of these classes:

    public TextBoxInput(int xLocation, int yLocation, string target, string label, int boxWidth)
    {
    this.Controls.Add(inputLabel);
    this.Controls.Add(inputBox);
    this.Name = "Testnamel";
    this.AutoSize = true;
    this.inputLabel.Text = label;
    this.inputLabel.AutoSize = true;
    int width = inputLabel.Width;
    this.inputLabel.AutoSize = false;
    inputLabel.Width = width;
    inputLabel.Height = inputBox.Height;
    this.inputBox.Width = boxWidth;
    this.inputBox.Location = new Point(inputLabel.Width, 0);
    this.inputLabel.Location = new Point(0, 0);
    Point p = new Point((xLocation - inputLabel.Width), (yLocation - (inputBox.Height/2)));
    this.PropertyName = target;
    this.inputLabel.TextAlign = ContentAlignment.MiddleLeft;
    this.Location = p;
    this.inputBox.LostFocus += new EventHandler(inputBox_LostFocus);
    this.inputBox.KeyDown += new KeyEventHandler(inputBox_KeyDown);
    this.modelChanged += new ViewDelegates.ModelChangedEventHandler(UseNewData);
    }

    edit: Weird, it works if the control instantiated last is added first.. Any idea why?
    Attached Images Attached Images
    Last edited by CyberRascal; August 5th, 2008 at 12:32 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured