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 8298103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:38:56+00:00 2026-06-08T15:38:56+00:00

If two Window is opened mainly A and B, how to close Window A

  • 0

If two Window is opened mainly A and B, how to close Window A using code that written on Window B.

  • 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-08T15:38:57+00:00Added an answer on June 8, 2026 at 3:38 pm

    Your best bet would be to create a property on Window B that you pass the creating Window to. Something like this. I have a Window named MainWindow and a second Window named Window2.

    Main Window

    namespace WpfApplication1
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            Window2 secondForm;
    
            public MainWindow()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, RoutedEventArgs e)
            {
                secondForm = new Window2();
                secondForm.setCreatingForm =this;
                secondForm.Show();
            }
        }
    }
    

    Window2

    namespace WpfApplication1
    {
        /// <summary>
        /// Interaction logic for Window2.xaml
        /// </summary>
        public partial class Window2 : Window
        {
            Window creatingForm;
    
            public Window2()
            {
                InitializeComponent();
            }
    
            public Window setCreatingForm
            {
                get { return creatingForm; }
                set { creatingForm = value; }
            }
    
            private void button1_Click(object sender, RoutedEventArgs e)
            {
                if (creatingForm != null)
                    creatingForm.Close();
    
            }
    
        }
    }
    

    In respose to your comment, closing a window that was created by another form is as easy as calling the Close Method of the created Form:

    namespace WpfApplication1
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            Window2 secondForm;
    
            public MainWindow()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, RoutedEventArgs e)
            {
                if (secondForm == null)
                {
                    secondForm = new Window2();
                    secondForm.Show();
                }
                else
                    secondForm.Activate();
            }
    
            private void button2_Click(object sender, RoutedEventArgs e)
            {
                if (secondForm != null)
                {
                    secondForm.Close();
                    secondForm = new Window2();
                    //How ever you are passing information to the secondWindow
                    secondForm.Show();
                }
    
            }
        }
    }
    

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

Sidebar

Related Questions

I have two window form applications written in C, one holds a struct consisting
I have the following code which creates a simple window with two buttons which
I have a winforms app that initially displays a window with two file dialog
I have two images on a WPF window that are on top of each
A window has a Grid with two columns. The left column contains a control
I have two different styles for my window: Regular - window has title bar
I want to open two different links images in one window on one click.
I have the following extJs window which has two tabs in it. One of
I have a page with two buttons, one Button opens a popup window with
Issue Weird problem. We've got two forms: the main application window and a settings

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.