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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:58:37+00:00 2026-06-07T19:58:37+00:00

I have two Forms, my main form is Form1 and my secondary form shown

  • 0

I have two Forms, my main form is Form1 and my secondary form shown on demand as a dialog is Form2.
Now if I call Form2 it shows always up in the upper left corner on my screen. First time I thought my form isn’t there at all, but then I saw it hanging in the upper screen corner. I would like to show my form at the current mouse position where the user clicks a context menu to show up the modal dialog.
I have already tried different things and searched for code samples. But I found nothing besides thousand of different codes on how to get the actual mouse position in different ways which I already know. But this position is anyway always relative to the screen, the main form, the control or whatever the current context is. Here my code (the desktop positioning which I also tried doesn’t work and center-to-screen centers the form only, so I left the property to Windows.Default.Position):

        Form2 frm2 = new Form2();
        frm2.textBox1.Text = listView1.ToString();
        frm2.textBox1.Tag = RenameFile;
        DialogResult dlgres=frm2.ShowDialog(this);
        frm2.SetDesktopLocation(Cursor.Position.X, Cursor.Position.Y);
  • 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-07T19:58:40+00:00Added an answer on June 7, 2026 at 7:58 pm

    Your problem is that your first call: frm2.ShowDialog(this); and then call frm2.SetDesktopLocation which in fact only gets called after the form (frm2) has already closed.

    ShowDialog is a blocking call – meaning that it returns only when the form your are calling ShowDialog on closes. So you will need a different approach to setting the form position.

    Probably the easiest way to accomplish that would be to create a second constructor on your Form2 (that you want positioned) which takes two parameters, for the X and Y coordinates.

    public class Form2
    {
    
        // add this code after the class' default constructor
    
        private int desiredStartLocationX;
        private int desiredStartLocationY;
    
        public Form2(int x, int y)
               : this()
        {
            // here store the value for x & y into instance variables
            this.desiredStartLocationX = x;
            this.desiredStartLocationY = y;
    
            Load += new EventHandler(Form2_Load);
        }
    
        private void Form2_Load(object sender, System.EventArgs e)
        {
            this.SetDesktopLocation(desiredStartLocationX, desiredStartLocationY);
        }
    

    Then, when you create the form to display it, use this constructor instead of the default one:

    Form2 frm2 = new Form2(Cursor.Position.X, Cursor.Position.Y);
    frm2.textBox1.Text = listView1.ToString();
    frm2.textBox1.Tag = RenameFile;
    DialogResult dlgres=frm2.ShowDialog(this);
    

    You can also try using this.Move(...)' instead of 'this.SetDesktopLocation in the Load handler.

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

Sidebar

Related Questions

I have two forms, let's call them Main and Form2 . Main form consists
I have two forms in my project, form1 and form2. I have added a
I have two forms and form1 needs to get data from form2 , i
I have two forms, one is the main form and the other is an
I have two forms(one main form,and one submain form).I'd like to do something like
I have two forms,one is main and other is inherited form main.Lets say I
I have two forms, the main form and a form named FrmSteg. I added
I have a winforms app with a main form (fMain) and two child forms
I have two forms. The first form Main has 2 buttons and a link
I have a main div on two pages ie page1.php and form.php page1.php <div

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.