MDI Parent-Child Multiple Events Firing

JDM

Joined
Feb 8, 2017
Messages
1
Reaction score
0
I am using Visual Studio 2010 Professional.

I've created an MDI interface.

In the parent ("MainForm") I have the following code:

Event CallFontChange()

And then the subroutine raising the event...
Private Sub ChangeFontToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles ChangeFontToolStripMenuItem.Click
Try
RaiseEvent CallFontChange()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub


In the child ("GCNDashboard") form, I have the following code:
Public Sub New()
' This call is required by the designer.
InitializeComponent()
AddHandler MainForm.CallFontChange, AddressOf ChangeFont
' Add any initialization after the InitializeComponent() call.
End Sub

And then the subroutine referencing the event handler...
Public Sub ChangeFont()
Try
Dim FontSet As New System.Windows.Forms.FontDialog
FontSet.Font = DataGrid1.DefaultCellStyle.Font
FontSet.ShowDialog()
Me.DataGrid1.DefaultCellStyle.Font = New Font(FontSet.Font.Name.ToString, FontSet.Font.SizeInPoints, FontSet.Font.Style)
DataGrid1.Refresh()
DataGrid1.AutoResizeColumns()
DataGrid1.AutoResizeRows()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

I put this in the form_closing event...
Private Sub GCNDashBoard_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
RemoveHandler MainForm.CallFontChange, AddressOf ChangeFont
End Sub


My issue is, when I click the ChangeFontToolMenuItem, the font dialog shows up once. I select the new font, size and style; then click "OK". Another font dialog shows up and again, I select the new font, size and style. In the DataGridView (named "DataGrid1"), I don't see the font change the first time but do see it change the second time. Obviously I only want the font dialog to appear once and make the changes the first time... You can see from my "butchered code" that I have tried several approaches and have finally reached the end of my ability to fix it. Can anyone help me with this?
 
Back
Top