cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

C# SAPbouiCOM: SaveFileDialog shows behind SAP window.

Peach14
Explorer
0 Likes
372

SaveFileDialog shows and can be used but it shows behind the SAP window.

I've tested run with C# in Visual Studio and it works very well being in front of the SAP window. But after added it with Lightweight Deployment, it became behind.

Here is the code I use,

 

System.Threading.Thread thread = new System.Threading.Thread(() => {
    using (System.Windows.Forms.SaveFileDialog saveFileDialog = new System.Windows.Forms.SaveFileDialog())
    {
        System.Windows.Forms.Form form = new System.Windows.Forms.Form();
        form.TopMost = true;
        saveFileDialog.ShowDialog(form);
    }
}
thread.SetApartmentState(System.Threading.ApartmentState.STA);
thread.Start();

 

 

 

 

Accepted Solutions (1)

Accepted Solutions (1)

Johan_Hakkesteegt
Active Contributor

Hi,

You can test adding form.TopLevel:

System.Threading.Thread thread = new System.Threading.Thread(() => {
using (System.Windows.Forms.SaveFileDialog saveFileDialog = new System.Windows.Forms.SaveFileDialog())
{
System.Windows.Forms.Form form = new System.Windows.Forms.Form();
form.TopLevel = true;
form.TopMost = true;
saveFileDialog.ShowDialog(form)
}
}
thread.SetApartmentState(System.Threading.ApartmentState.STA);
thread.Start();

Regards,

Johan

Peach14
Explorer

Thanks for the answer. I've tried it and it still doesn't work. But I searched for solutions in other topics and found this one that weirdly works by setting visible as true and the rest work like a magic.

 

System.Threading.Thread thread = new System.Threading.Thread(() => {
    using (System.Windows.Forms.SaveFileDialog saveFileDialog = new 
    System.Windows.Forms.SaveFileDialog())
    {
        System.Windows.Forms.Form saveForm = new System.Windows.Forms.Form();
        saveForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
        saveForm.ControlBox = false;
        saveForm.Activate();
        saveForm.BringToFront();
        saveForm.Visible = true;
        saveForm.Width = 0;
        saveForm.Height = 0;
        saveForm.TopMost = true;
        saveForm.Focus();

        System.Windows.Forms.DialogResult dialogResult = saveFileDialog.ShowDialog(saveForm);

        System.Threading.Thread.Sleep(100);
    }
});

thread.IsBackground = false;
thread.Priority = System.Threading.ThreadPriority.Highest;
thread.SetApartmentState(System.Threading.ApartmentState.STA);
thread.Start();

 

 

 

 

Answers (0)