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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:30:13+00:00 2026-05-26T10:30:13+00:00

I have a winforms app with a main form (fMain) and two child forms

  • 0

I have a winforms app with a main form (fMain) and two child forms (fLogin and fAdmin). fLogin is displayed using this code which is in a button click event handler for a button on the main form:

// show login form; pass the main form in as an argument
fLogin formLogin = new fLogin(this);
formLogin.StartPosition = FormStartPosition.CenterParent;
formLogin.ShowDialog(this);

In the constructor for fLogin, I assign the main form to a private member level variable.

// fLogin
fMain _mainForm;

// fLogin constructor
public fLogin(fMain mainForm)
{
    InitializeComponent();
    _mainForm = mainForm;
}

As you might imagine, fLogin is a small form with textboxes for a username and password and a couple of buttons. When my users enter their credentials and click the OK button, fLogin will validate the information with a server and if the information is good, fLogin will disappear and fAdmin will be displayed. Currently, I’m displaying fAdmin like this:

// hide formLogin right away
this.Hide()

// show admin form
fAdmin formAdmin = new fAdmin();
formAdmin.StartPosition = FormStartPosition.CenterParent;
formAdmin.Show(_mainForm); // pass main form as owner of admin form

// close formLogin
this.Close();

I can’t set formAdmin.Parent = _mainForm and get the dialog to magically center itself. So I’m passing _mainForm to formAdmin.Show() as the owner of formAdmin but that doesn’t seem to help with regard to getting formAdmin centered. Is there an easy way to cause formAdmin to be displayed at the center of the main form?

  • 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-05-26T10:30:14+00:00Added an answer on May 26, 2026 at 10:30 am

    I think you need to restructure how you are doing this just a bit, instead of displaying fAdmin from within fLogin, close fLogin and then open fAdmin from fMain. If this doesn’t work you can manually center if by calculating the point for the upper left corner of fAdmin and set this point as fAdmin’s Location. I’ve had to do this in the past when I’ve encountered similar issues. To calculate the upper left corner for fAdmin so that it will be centered on fMain, use the following:

    Point p = new Point(0, 0);
    p.Y = (fMain.Height / 2) - (fAdmin.Height / 2);
    p.X = (fMain.Width / 2) - (fAdmin.Width / 2);
    fAdmin.Location = p;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a winforms app and the main (and only) form has several buttons.
Scenario I have a C# Win Forms App, where the Main Form contains a
I have a simple WinForms type application (main form, couple of sub-forms, minimize to
I have a winforms app using a trackbar. The BackColor property is available for
I have a WinForms app built using Visual Studio 2005, including the crystal reports
I have a solution consisting of a main winforms app, with associated internally written
I have a WinForms app. This app has a Preferences section where the user
I'm trying to write a simple Compact Framework winforms app. The main form has
I have a WinForms app written in C# with .NET 3.5. It runs a
I have a winforms app and i want to keep track of every time

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.