Results 1 to 4 of 4

Thread: ZedGraphControl issues when converting a startup form into MDI form

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2016
    Posts
    2

    ZedGraphControl issues when converting a startup form into MDI form

    I have a VS project with several forms and a module to handle most variable declarations.

    1. The startup form ("Form1") incorporates a serial port to retrieve external data at 1-second intervals.
    2. The data is then plotted in ZedGraphControls in Form1. It worked flawlessly at first.

    3. Then I experimented with making (what I thought) would be a minor aesthetic change in attempt to improve the layout of the project when multiple forms are loaded: add an MDI parent form ("MDParent1") from which I now generate a new instance of Form1 as a child form ("NewForm1") upon loading MDIParent1:


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

    Dim NewForm1 As New Form1()
    NewForm1.MdiParent = Me
    NewForm1.Show()
    NewForm1.BringToFront()
    End Sub



    4. Now, when I load "NewForm1" and poll for external data, the ZedGraphControls do not plot the retrieved data any more (I have verified that the data is still being retrieved correctly). As far as I can tell no other changes were made.
    5. I verified that if I re-define Form1 as the startup form, the ZedGraphControls still work as they did before incorporating the MDIParent form and trying to use them in the NewForm1 child form.

    Any ideas what I might be doing wrong, or suggestions for further troubleshooting? Thanks for your input.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,350

    Re: ZedGraphControl issues when converting a startup form into MDI form

    My guess is that this is related to default form instances. Where is the code that reads the data and updates the form located? Can you post that code? Most likely that code refers to the default instance of Form1.

    The application's startup form is the default instance of its type but the code you posted above does not, thus your code might be referring to an instance of Form1 other than the one you're looking at. You could change this:
    vb.net Code:
    1. Dim NewForm1 As New Form1()
    2. NewForm1.MdiParent = Me
    3. NewForm1.Show()
    4. NewForm1.BringToFront()
    to this:
    vb.net Code:
    1. Form1.MdiParent = Me
    2. Form1.Show()
    3. Form1.BringToFront()
    to use the default instance and see if that fixes your issue. Personally, I like to avoid default instances altogether and most other experienced developers do too. They can make certain things easier if you don't know the alternatives but there's never a specific need to use them.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2016
    Posts
    2

    Re: ZedGraphControl issues when converting a startup form into MDI form

    I incorporated your suggestion and that fixed the problem. Thank you very much!

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,350

    Re: ZedGraphControl issues when converting a startup form into MDI form

    You might like to follow the Blog link in my signature below and check out my post on Default Form Instances to learn a bit more and hopefully avoid getting burned by default instances again. There's also my three part post on Data Among Multiple Forms that shows how data can be passed among forms using default instances and then the alternatives.

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