• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 229
  • Last Modified:

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.
0
shawnlehner
Asked:
shawnlehner
1 Solution
 
Fernando SotoCommented:
You can cause the area of the control to call the paint event by doing the following after you have the width.

NameOfControl.Invalidate()
0
 
wguerramCommented:
'Also call update after invalidate to syncronize it.

NameOfControl.Invalidate()
NameOfControl.Update()
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
...or just call the controls Refresh() method:

    NameOfControl.Refresh()
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
shawnlehnerAuthor Commented:
ok how would I refresh an object on frmMain from a different form?
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
0
 
shawnlehnerAuthor Commented:
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()
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
You need an instance of frmMain to work with.  In your example you have declared mainForm but have not instantiated it with the New keyword.  

In my example I pass instance of frmMain to an instance of Form2 using this line:

    f2.fMain = Me

Then in foo() on Form2, we are able to manipulate frmMain through our reference.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now