1

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?

user1017477
  • 161
  • 2
  • 13

1 Answers1

1

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

Steve
  • 213,761
  • 22
  • 232
  • 286
  • Steve, thanks for the response. I have updated the AddHandler accordingly.. DUH! been staring at it too long. However my control still is not updating? I have tried Me.Update() within the RefreshGraph Sub right after the call to CreateGraph and still no luck?? – user1017477 Feb 06 '13 at 16:26
  • Have you put a breakpoint inside the RefreshGraph method and checked if the method is called? – Steve Feb 06 '13 at 16:30
  • yes, and and I have followed the CreateGraph method all the way through to ensure that new data is being loaded. I even put a little MsgBox after and it pops up like it should... – user1017477 Feb 06 '13 at 16:32
  • OK, just figured it out. This is my first time using the Dockpanel Suite and there is a refresh method that must be called on the dockpanel control in order to refresh its contents. Thanks again for your assistance. I have updated the RefreshGraph Sub in the above code accordingly. – user1017477 Feb 06 '13 at 16:37
  • Without the code of CreateGraph is difficult to say. Do you have called `zedGraphControl1.Invalidate()` and `zedGraphControl1.Refresh()` inside the CreateGraph method? – Steve Feb 06 '13 at 16:44
  • Steve, see my comment above and my updated code. I had call the DockPanel.Refresh() method thus updating all controls within the dockpanel. Thanks again! – user1017477 Feb 06 '13 at 16:51