Click here to Skip to main content
15,867,832 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Recently, I met a curious thing on VisualStudio.
It was related display orders.
When I created a code which can be popupping up Excel, the behaviors were different between VisualStudio and non VisualStudio.

The code is like writing in a form's caption after Excel pops up.

Start on a windows form project and add the reference setting of "Microsoft Excel 14.0 Object Library" in COM tab.
Then adding a button with VisualStudio and paste the below code on the button's codebehind.

C#
Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();

Microsoft.Office.Interop.Excel.Workbook workbook = excel.Workbooks.Add(Type.Missing);

Microsoft.Office.Interop.Excel.Worksheet sheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.ActiveSheet;

//Cell Editing
((Microsoft.Office.Interop.Excel.Range)sheet.Cells[1, 2]).Value2 = string.Empty;

excel.WindowState = Microsoft.Office.Interop.Excel.XlWindowState.xlMaximized;

excel.Visible = true;

this.Text = "End";


If this is waked up from VisualStudio and press the button, the Excel might be appearing in front of the form.
However quitting VisualStudio and launch it as Exe, the Excel is supposed to go behind the form.

Does anyone explain why such things happened?
Or something my environment was broken?

My environment:
Windows 7 Professional
Microsoft Excel 2010
VisualStudio 2010
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900