user1017477
user1017477

Reputation: 161

Handling Event - form/control not updating?

First off, I do not work with winform development full time so don't bash me too bad...

As the title somewhat depicts, I am having an issue refreshing the controls on a form after an event has been raised and captured.

On "Form1" I have a Dockpanel and am creating two new forms as shown below:

Public Sub New()
    InitializeComponent()

    dpGraph.DockLeftPortion = 225
    dpGraph.BringToFront()

    Dim frmT As frmGraphTools = New frmGraphTools()
    Dim frmG As frmGraph = New frmGraph()

    AddHandler frmT.UpdateGraph, AddressOf frmG.RefreshGraph
    frmT.ShowHint = DockState.DockLeft
    frmT.CloseButtonVisible = False
    frmT.Show(dpGraph)

    frmG.ShowHint = DockState.Document
    frmG.CloseButtonVisible = False
    frmG.Show(dpGraph)
End Sub

Within the frmGraphTools class I have the following delegate, event, and button click event defined:

Public Delegate Sub GraphValueChanged(ByVal datum As Date)
Public Event UpdateGraph As GraphValueChanged

Private Sub btnSaveMach_Click(sender As Object, e As EventArgs) Handles btnSaveMach.Click
    RaiseEvent UpdateGraph(dtpJobDate.Value.ToString())
End Sub

Within the frmGraph class I have the following Sub defined:

Public Sub RefreshGraph(ByVal datum As Date)
    CreateGraph(datum)
    frmGraphBack.dpGraph.Refresh()
End Sub

I have a ZedGraph control on the frmGraph form that is supposed to be refreshed/redrawn upon the button click as defined on frmGraphTools. Everything seems to working, the RefreshGraph Sub within frmGraph is being executed and new data is pushed into the ZedGraph control however, the control never updates. What must be done to get the frmGraph form or the ZedGraph control to update/refresh/redraw properly?

Upvotes: 1

Views: 684

Answers (1)

Steve
Steve

Reputation: 216293

Pass the reference to RefreshGroup method from the correct instance of frmGraph

 AddHandler frmT.UpdateGraph, AddressOf frmG.RefreshGraph

also this call should be flagged by the compiler because you are passing a string instead of a Date

 RaiseEvent UpdateGraph(dtpJobDate.Value.ToString())

probably you have Option Strict Off

Upvotes: 1

Related Questions