Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8105721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:14:24+00:00 2026-06-06T00:14:24+00:00

I am trying to update a label from one form to another. the code

  • 0

I am trying to update a label from one form to another. the code is compiling fine but not updating?

Class MainWindow 

    Private Sub Window_Loaded(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
        Dim frm As New Window1
        frm.Show()
    End Sub
End Class

second form:

Public Class Window1

    Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
        My.Windows.MainWindow.Label1.Content = "dsfdsfsdf"
        My.Windows.MainWindow.Label1.UpdateLayout()
    End Sub
End Class

it doesn’t update the main form’s label… hope that makes it clearer

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T00:14:26+00:00Added an answer on June 6, 2026 at 12:14 am

    So here’s the code that you actually need:

    Public Class Window1

    Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
        DirectCast(Application.Current.MainWindow, MainWindow).Label1.Content = "test"
    End Sub
    

    End Class

    I’m not sure what the My.Windows collection is, but the Application.MainWindow gives you a reference to the window that is set as the start up object in the project properties (or the one you set in your app.xaml.cs file). Previously you were probably getting a reference to a different instance of the Window1 class, hence it was running and not throwing an exceptions, but since it wasn’t the actual visible instance of the window then you didn’t see any changes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im trying to change the text of a label from a class but have
Im trying to select the span by using the (.class) selector but for one
Trying to update some old code from live() to use on() and something is
I was trying this from some time, but I am not able to get
Im trying to update a table with the following code. If I change WHERE
I trying to update a model on a callback but the validation is causing
When trying to update a subversion working copy from Netbeans, I get the following
Im trying to update the contents of an element after running some php code.
I'm trying to update my code to use cv2.SURF() as opposed to cv2.FeatureDetector_create(SURF) and
Following on from a previous post , I'm trying to update a database field

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.