Question

I use several instances (myForm1, myForm2,etc...) of the same MDIChild form (frmChart) to display different MSCharts:

frmMain: 

Private Sub Open()

        dim myForm1 as frmChart
        myForm1.Show

        dim myForm2 as frmChart
        myForm2.Show

End sub

The problem happens when I try to save the MSChart of one opened instance, because I call a frmChart.SaveChart() function which resizes a picturebox and then the Form_Load() event is invoked, so a new extra frmChart is opened.

frmChart:

Public Sub SaveChart()
   picGrapgh.Height = chChart.Height
   picGrapgh.Width = chChart.Width
   picGraph.Autoredraw = True
   picGraph.Picture = picGraph.Image
   SavePicture picGraph.picture, FileName
End Sub

When I call that sub, it invokes the Form_Load() of the frmChart. This only happens when I use form instances (myForm1). Once I use any property of the PictureBox control of the frmChart it launches the Form_Load event. How could I prevent it?.

Thank you very much in advance.

Regards, Ruben

Was it helpful?

Solution

There are 2 problems:

dim myForm1 as frmChart

This just declares that myForm1 will be of the Type frmChart if/when one is created (instanced). To create an actual instance of frmChart:

dim myForm1 as New frmChart

Since myFormN is now an instance of frmChart, you can call those procedures directly on/thru the instance variable:

myForm1.SaveChart
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top