Link to home
Start Free TrialLog in
Avatar of shawnlehner
shawnlehnerFlag for United States of America

asked on

Refreshing Object on Form

I am using a graphics box for a graphic load bar.... when I change the width what is the best way to refresh the bar because sometimes it does not update.
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

You can cause the area of the control to call the paint event by doing the following after you have the width.

NameOfControl.Invalidate()
Avatar of wguerram
wguerram

'Also call update after invalidate to syncronize it.

NameOfControl.Invalidate()
NameOfControl.Update()
...or just call the controls Refresh() method:

    NameOfControl.Refresh()
Avatar of shawnlehner

ASKER

ok how would I refresh an object on frmMain from a different form?
You need a reference to frmMain from your secondary form:

Public Class frmMain
    Inherits ...

    Public Sub Button1_Click(...) Handles Button1.Click
        Dim f2 As New Form2
        f2.fMain = Me
        f2.Show()
    End Sub

End Class


Public Class Form2
    Inherits ...

    Public fMain As frmMain

    Private Sub foo()
        If Not (fMain Is Nothing) Then
            fMain.Label1.Text = "Something..."
            fMain.Label1.Refresh()
        End If
    End Sub

End Class
Below code does not work... gives me an invalid instance code... help?        

        Dim mainForm As frmMain

        overallRun = overallRun + EventsFinished
        overallWidth = Convert.ToInt32((overallRun / overallCount) * 436)
        mainForm.loadbarOverall.Width = overallWidth
        mainForm.loadbarOverall.Invalidate()
        mainForm.loadbarOverall.Refresh()
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial