Your problem is that your first call is: frm2.ShowDialog(this);
and then call frm2.SetDesktopLocation
, which is actually only called after the form (frm2) is already closed.
ShowDialog is a blocking call - this means that it returns only when the form that you call ShowDialog closes. Therefore, you will need a different approach to adjust the position of the form.
Probably the easiest way to achieve this would be to create a second constructor on your Form2 (which you want to place) that takes two parameters for the X and Y coordinates.
public class Form2 {
Then, when you create a form to display it, use this constructor instead of the standard 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 a load handler.
source share