Question How to pass label from one form to another?

AlexC

New member
Joined
Mar 22, 2014
Messages
2
Programming Experience
Beginner
Hello,

i want to pass a label from form1 to form2.

When i click a "download" button in form1, a download will start and:
- a label shows the progress of the download;
- a new form (form2) is opened that contains a animated gif representing the download progress.
When the download finishes, form2 closes.

I would like to show that label in form2, below the animated gif (i've created a label for that but i can't update it with the value of the label that is in form1)

This is the code that i'm using to show the download progress in a label (named labelDownloaded2), in form1.

C#:
private void ProgressChanged_processXPL(object sender, DownloadProgressChangedEventArgs e)        
        {
            [B]labelDownloaded2[/B].Text = string.Format("{0} MB's / {1} MB's",
           (e.BytesReceived / 1024d / 1024d).ToString("0.00"),
           (e.TotalBytesToReceive / 1024d / 1024d).ToString("0.00"));
        }

How can i show this label in form2?

thanks in advance!
 
Last edited:
You're not going to show the same Label in both forms. You're simply going to display the text in two different Labels, one on each form. To learn how to pass data between forms properly, I suggest that you follow the Blog link in my signature below and check out my post on Data Among Multiple Forms. Make sure that you read all three parts because, if you want to do it properly, part 3 is really what you should be following.
 
Thanks for helping, I've learn a lot from reading your post.

After several hours trying many different solutions available around the internet without success, I've found this simple crystal clear tutorial, the only one that actually worked for me.
Passing value from one to another form

I hope it help others too.

Cheers
 
Last edited:
Back
Top Bottom