强制将excel窗口置于最前面? [英] force to bring excel window to the front?

查看:378
本文介绍了强制将excel窗口置于最前面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用C# .NET开发的小型应用程序,可以处理excel表格,我不知道为什么有些用户不断告诉我,尽管他们设置了可见为真,窗口状态为最大化.

i have a small application developed in C# .NET that manipulate excel sheets, I don't know why some users keep telling me that when they open the excel file the window doesn't appear on front/top although I set the visible to true and the window state on maximized.

这是读取 excel 文件的函数:

public static void OpenExcel(string fileName, bool visibility, FunctionToExecute fn = null)
{
    string addInPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Microsoft\\AddIns\\mDF_XLcalendar.xla");

    deleg = fn;
    app = new Excel.Application();

    app.Workbooks.Open(addInPath);
    app.Workbooks.Open(fileName);

    app.ScreenUpdating = true;
    app.DisplayAlerts = true;
    app.Visible = visibility;
    app.UserControl = true;
    app.WindowState = Excel.XlWindowState.xlMaximized;

    EventDel_BeforeBookClose = new Excel.AppEvents_WorkbookBeforeCloseEventHandler(application_WorkbookBeforeClose);
    EventSave_BeforeBookClose = new Excel.AppEvents_WorkbookBeforeSaveEventHandler(Open_ExcelApp_WorkbookBeforeSave);

    app.WorkbookBeforeClose += EventDel_BeforeBookClose;
    app.WorkbookBeforeSave += EventSave_BeforeBookClose;     
} 

有什么想法吗?

推荐答案

我会尝试通过以下方式激活Excel窗口

I would try to activate the excel window by

app.ActiveWindow.Activate();

如果这不起作用,您可能会在

If this doesn't work you might find other solutions (involving Native WinAPI calls) at this thread at http://social.msdn.microsoft.com/

这篇关于强制将excel窗口置于最前面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆