0

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");
        }

    }
Lennart
  • 9,657
  • 16
  • 68
  • 84
Alpha
  • 127
  • 2
  • 14
  • hard to tell without the code - include a minimal, complete example – Cee McSharpface Oct 11 '18 at 10:21
  • 2
    This is caused by a misbehaving shell extension installed on your machine. It calls SetProcessDPIAware(), very naughty. You can chase it down with SysInternals' Autoruns utility, but consider that it is high time to start creating dpiAware programs. Very important today. https://stackoverflow.com/questions/13228185/how-to-configure-an-app-to-run-correctly-on-a-machine-with-a-high-dpi-setting-e – Hans Passant Oct 11 '18 at 10:26
  • @dlatikay i have added the code for the savefiledialog – Alpha Oct 11 '18 at 10:32
  • @HansPassant Thank you that worked – Alpha Oct 11 '18 at 10:38

1 Answers1

1

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

Alpha
  • 127
  • 2
  • 14