0

When I start up the program I have added code to open a file dialog box, but doing this results in the main form being sent behind Visual Studio(and other open programs) once a file has been selected. I have tried using this.BringToFront() but this doesn't seem to work. The program currently only has one form as well, how would I bring this to the front when the program starts?

public Form1()
{
    InitializeComponent();
    InitialiseDataGrid();
    selectFile();
    readData();
    this.BringToFront();
}

selectFile() is a function that selects a file using a file dialog box, readData() is a function that reads the data from the text file into a dataGridView.

JustSomeGuy
  • 3,677
  • 1
  • 23
  • 31
Kelsall
  • 57
  • 2
  • 14

3 Answers3

3

You should past the owner window's instance while Opening The dialog window. example code:

var file = new OpenFileDialog();
file.ShowDialog(this);
Gaurav Sharma
  • 586
  • 3
  • 10
1

You can use

this.TopMost = true;
MD SHAHIDUL ISLAM
  • 14,325
  • 6
  • 82
  • 89
0

You're juggling with different applications: VS and your program. The released version of the program probably won't run through VS anyway.

Bring it to the foreground:

this.Activate();

Use it with caution.

Gabe
  • 961
  • 1
  • 10
  • 23