Hi, i'm new to vb but acquainted with programming in java, C, and other languages. I´m developing an application and i'm having difficulties at commanding controls from different forms.
It's like this:
Form1 has some buttons and charts, and in Form2 it's a "Settings" form to select the category and series for the charts. When i close the Form2 i need to activate some controls like buttons in Form1 and the problem is that at run-time i can call functions like this one:
Public Sub EnableButton() button1.Enabled = True End Sub
Public Sub BeforeClosing() Form1.EnableButton() Me.close() End Sub
Using breaks i can see that they execute and the properties of the button change but after the close event of Form2, the properties of the button1 control become unchanged.
The same is happening to my chart but a little weirder (for me at least)
At the global variables i have:
Dim newChart As System.Windows.Forms.DataVisualization.Charting.Chart
At ButtonX_Click i create a new chart and define some properties and in the end i activate the Form2
Private Sub ButtonSettings_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSettings.Click newChart = New System.Windows.Forms.DataVisualization.Charting.Chart newChart.Visible = False CType(newChart, System.ComponentModel.ISupportInitialize).BeginInit() CType(newChart, System.ComponentModel.ISupportInitialize).EndInit() Me.Controls.Add(newChart) newChart.Parent = Me newChart.Location = New System.Drawing.Point(Me.Location.X, Me.Location.Y) newChart.Height = Me.Height - 25 newChart.Width = Me.Width newChart.Name = "grafico" newChart.Text = "grafico" newChart.BorderlineWidth = 1 newChart.BorderlineColor = Color.LightSteelBlue newChart.BorderlineDashStyle = DataVisualization.Charting.ChartDashStyle.Solid Form2.Show() End Sub
When i leave Form2 i do:
Private Sub B_OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B_OK.Click [I] ... SOME CODE ...[/I] Form1.button_ShowChart.PerformClick() Me.Close() end sub
Finally at Form1 i create a ChartArea and when i want to use the chart it says that the chart is NULL
Private Sub button_ShowChart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button_ShowChart.Click Dim ChartArea1 As New System.Windows.Forms.DataVisualization.Charting.ChartArea ChartArea1.Visible = False ChartArea1.Name = newTable.TableName & "_" & [B][U]newChart.ChartAreas.Count[/U][/B] [I] ... SOME MORE CODE ... [/I] end sub
So the sequence is:
Execute: Button_Settings_Click -> initialize chart and Form2.Show()
Happens: Chart Initialized and properties are changed
Execute: Button_OK_Click -> Form1.Button_ShowChart.PerformClick() and Me.Close()
Happens: Sub .PerformClick() executes but values are not changed
Execute: Button_ShowChart_Click -> Add data to Chart
Happens: Chart is found as NULL and properties are lost
I can't understand why does this happens, why does the controls properties are lost if they are executed???
Thanks in advance.
Edited 6 Years Ago by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).