Childform misbehaving? Ignoring location commands. RRS feed

  • Question

  • I have used the following code to try to have to childforms appear in a parent form. However, when i run the program, the child forms do not go to the specified sizes nor locations.

    Dim childForm As Integer = 1
    Dim childforms(1) As Polar_Curve
    Dim childforms2(1) As polar_curve_edit

    Private Sub MDIParent1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    childForm += 0

     childforms(childForm) = Polar_Curve

    childforms2(childForm) = New polar_curve_edit

    childforms(childForm).StartPosition = FormStartPosition.Manual
    childforms(childForm).Location = New System.Drawing.Point(0, 0)
    childforms(childForm).Size = New System.Drawing.Size(800, 569)

    childforms2(childForm).StartPosition = FormStartPosition.Manual
    childforms2(childForm).Location = New System.Drawing.Point(860, 78)

    childforms(childForm).Text = "PolarCurve" '& Str(childForm)
    childforms2(childForm).Text = "Edit" '& Str(childForm)
    'setting title for child windows and incrementing the number with an array
    childforms(childForm).MdiParent = Me
    childforms2(childForm).MdiParent = Me

    End Sub

    Friday, August 11, 2006 12:40 AM

All replies

  • // childForm += 0

    What's that supposed to achieve ?

    DO you want these forums embedded as children ? Because if you do, you need to add them to the collection that's part of the form.  Otherwise, you're floating them on the screen using absolute co-ordinates, not co-ordinates that relate to the parent form.

    // childforms(childForm) = Polar_Curve

    // childforms2(childForm) = New polar_curve_edit

    Why do you have two arrays, each with one element ?


    Friday, August 11, 2006 1:11 AM
  • Accually, I was just trying to figure out what "childForm += 0" does.
    Friday, August 11, 2006 1:18 AM
  • I had to search on the internet to figure out that code. Not sure where i found it thou.

    How would you embed the 2 forms as children?
    Friday, August 11, 2006 1:21 AM
  • This is why you shouldn't just cut and paste code from the web.  I use the web all the time to help me figure out stuff, but any code I use, I understand fully.

    Here's how I do it in C#


    ImageViewer iv = new ImageViewer();

    iv.Item = item;

    iv.Name = "Viewer" + Controls.Count;

    iv.Location = new Point(0, 0);

    iv.Width = this.Width;

    iv.Height = this.Height;


    Basically, create a new control, set it's location and size, then add it to the Controls collection that exists on your form.  It's now a child control.

    I see you're setting the MDI child property, that may take the place of doing this for an MDI app ( I'm not sure ), but once you do that, then the framework is going to control the location of MDI children, you're not going to set them directly like that, I wouldn't think.  It's more likely the MDI framework has a property that lets you iterate over MDI child windows and work with their position/size


    Friday, August 11, 2006 1:27 AM
  • Dim iv As imageViewer = New ImageViewer
    iv.Item = item
    iv.Name = "Viewer" + Controls.Count
    iv.Location = New Point(0, 0)
    iv.Width = Me.Width
    iv.Height = Me.Height

    Ill try the above code and will post back in a couple of days. Im going out of town tomarrow for a couple of days.

    I also tried that code using to load the forms i already created but get an error when i debug that says:

    Top-level control cannot be added to a control.

    The error goes away when i remove that last line of code, but that causes the forms not to show up in the parent form.
    Friday, August 11, 2006 1:33 AM
  • The code you showed only works if the controls dont already exist, correct?

    I've been working on this graphing program and wanted to try to put the Grapher form and the graph edit form (and possibly another form) all into the parentform.
    Friday, August 11, 2006 1:47 AM
  • The only bit that assumes the control doesn't exist already is the bit where I call new on it.  The code all assumes the control is not part of hte form yet, however.

    Naturally, you cannot cut and paste my code, it's creating an instance of a class I wrote ( that you don't have ).  Substitute your own control name for the one I am creating.


    Friday, August 11, 2006 1:55 AM
  • Yah, I edited the code, I just forgot to show you that.  Im at school right now and left the vb files at home.  So Ill have to put the code here over the weekend or monday.
    Friday, August 11, 2006 12:50 PM
  • This is the code i used.

    Dim polarform As Polar_Curve = Polar_Curve
    'polarform.Item = item
    polarform.Name = "Polar Curve 2.0" + Controls.Count.ToString
    polarform.Location = New Point(0, 0)
    polarform.Width = Me.Width
    polarform.Height = Me.Height

    Dim polaredit As polar_curve_edit = polar_curve_edit
    'polarform.Item = item
    polaredit.Name = "Polar Curve 2.0" + Controls.Count.ToString
    polaredit.Location = New Point(500, 0)
    polaredit.Width = Me.Width
    polaredit.Height = Me.Height

    Dim polarview As Polar_List = Polar_List
    'polarform.Item = item
    polarview.Name = "Polar Curve 2.0" + Controls.Count.ToString
    polarview.Location = New Point(800, 0)
    polarview.Width = Me.Width
    polarview.Height = Me.Height
    Monday, August 14, 2006 11:50 PM
  • When i run it with the code above, the parentform shows up blank.

    Also, if i use the code


    for each of the three childforms, then go and debug, the program just freezes.

    "DO you want these forums embedded as children ? Because if you do, you need to add them to the collection that's part of the form.  Otherwise, you're floating them on the screen using absolute co-ordinates, not co-ordinates that relate to the parent form."

    If you mean as embed them when the program is compiled, I tried that but on one of the childforms I get an error saying Polar_curve is not defined, yet my other childforms dont give that error.
    Monday, August 14, 2006 11:51 PM
  • Well....
    Sunday, August 20, 2006 8:01 PM