Solved

refresh label

Posted on 2008-10-29
6
1,397 Views
Last Modified: 2012-06-27
hello experts,
i have an application whereby a label is reading the content of a text file. i added a refresh button which should refresh the content of the label. what is the code for refreshing koz i already tried lblDisplay.refresh without success
-------------------------Reading-----------------------------  Private Sub mnuOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuOpen.Click
 

 If lstDrafts.FocusedItem.Index = 0 Then

            Dim reader As StreamReader

            reader = File.OpenText("\Drafts\MessageNum0.txt")

            Dim contents As String = reader.ReadToEnd()

            lblDisplay.Text = contents

            lblDisplay.Visible = True

            reader.Close()

        End If

end sub

-------------------------Refreshing button------------------------------

    Private Sub mnuRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuRefresh.Click

        lblDisplay.Refresh()

        lblDisplay.Visible = False

    End Sub

Open in new window

0
Comment
Question by:Alv45525
  • 4
  • 2
6 Comments
 
LVL 8

Accepted Solution

by:
dampsey earned 125 total points
ID: 22838579
Refresh command, just redraws the current content of the label. It does not read the file again.

What you should do is, call the reading function again.
Private Sub mnuOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuOpen.Click

 

 If lstDrafts.FocusedItem.Index = 0 Then

       lblDisplay.Text = ReadTheFileContent()

       lblDisplay.Visible = True

 End If

end sub
 

private function ReadTheFileContent() as string

Dim reader As StreamReader

            reader = File.OpenText("\Drafts\MessageNum0.txt")

            Dim contents As String = reader.ReadToEnd()

            reader.Close()

            return contents

end function
 

    Private Sub mnuRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuRefresh.Click

       lblDisplay.Text = ReadTheFileContent()

   End Sub

Open in new window

0
 

Author Comment

by:Alv45525
ID: 22838778
hello dampsey, i tried it but still after reading the label does not get refresh
0
 
LVL 8

Expert Comment

by:dampsey
ID: 22838793
are you sure you change the content of the correct file and save it before refreshing?
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:Alv45525
ID: 22838804
look i have two txt files listed in a treeview. when the first 1 is selected,
label.visible= true and it displays content of txt 1

if button close(refresh) is selected, the label should clear its content, that is the txt1 and hide again.

when user select second txt file, label appears again and displays content of txt 2
0
 

Author Comment

by:Alv45525
ID: 22838867
thx 4 ur help dampsey..but i've been able to do it...

it wrote

lblDisplay.text = nothing
0
 

Author Closing Comment

by:Alv45525
ID: 31511558
Thx 4 ur help...i appreciate that u too the time 4 answering me
thX loads

tke care.N hpe to here frm u!
tke care
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now