Alpha
Alpha

Reputation: 127

savefiledialog.opendialog() minimizes form

Hi I just want to know why is this happening and how can I stop it from happening?

This is how it looks before i click the export data This is how it looks before i click the export data

enter image description here Then it minimizes the form somehow? This is a windows form with a user control in the middle. The windows form is set to this.WindowState = System.Windows.Forms.FormWindowState.Maximized

This is my code for the SaveFileDialog

private void btnExport_Click(object sender, EventArgs e)
    {

        Microsoft.Win32.SaveFileDialog ofd1 = new Microsoft.Win32.SaveFileDialog();
        ofd1.Filter = "Database Files (*.sqlite)|*.db";
        ofd1.FileName = "dbwaterworks.sqlite";
        // customize file dialog properties here

        if (ofd1.ShowDialog() == true)
        {

            var path = Path.GetFullPath(ofd1.FileName);
            var destinationCnx = "Data Source=" + path + "; Version=3;";
            using (var source = new SQLiteConnection("Data Source=dbwaterworks.sqlite; Version=3;"))
            using (var destination = new SQLiteConnection(destinationCnx))
            {
                source.Open();
                destination.Open();
                source.BackupDatabase(destination, "main", "main", -1, null, 0);

            }
        }
        else
        {
            MessageBox.Show("Canceled");
        }

    }

Upvotes: 0

Views: 126

Answers (1)

Alpha
Alpha

Reputation: 127

From @HansPassant comment, changing your main method to this

[STAThread]
static void Main() {
    if (Environment.OSVersion.Version.Major >= 6) SetProcessDPIAware();
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(new Form1());             // Edit as needed
}

[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool SetProcessDPIAware();

Will make it not minimized

Upvotes: 1

Related Questions