Hi,
Can anyone tell me how to disable Close(x) button in an excel application which is opened inside a wpf window.
Thanks & Regards,
Ramana
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted May 3, 2011, 7:05 AM
private void WorkbookBeforeCloseHandler(Excel.Workbook Wb, ref bool Cancel)
{
if (someCondition) Cancel = true;
}
RamanaPosted May 3, 2011, 6:39 AM
Thanks for ur reply. The code which u have posted will ensure that the WorkBook will not be closed , even I should not be able to close the Excel Application also.
Thanks & Regards,
Ramana
VulpesPosted May 3, 2011, 6:30 AM
xlApp.WorkbookBeforeClose += WorkbookBeforeCloseHandler;
private void WorkbookBeforeCloseHandler(Excel.Workbook Wb, ref bool Cancel)
{
Cancel = true;
}
RamanaPosted May 3, 2011, 4:40 AM
VulpesPosted May 2, 2011, 7:01 PM
However, a problem with trapping WM_CLOSE is that the user would then have no visible indication that the window couldn't be closed.
Sam HobbsPosted May 2, 2011, 6:43 PM
Even if there is a good reason to disable the close button, an experienced Windows developer would attempt to disable the close message instead of the close button. The close message can be sent in a variety of ways.
Ooops, I am sorry, Vulpes; this is implying that you are not an experienced Windows programmer and I know you and Abhimanyu are. I am trying to get Ramana to consider alternatives but I don't mean to diminish the experience and knowledge of others. I might be the one that misunderstands.
Mahesh ChandPosted May 2, 2011, 2:28 PM
VulpesPosted May 2, 2011, 10:24 AM
Whether it will behave the same when it's a child of a WPF window remains to be seen:
To re-enable the Close button call:
EnableMenuItem(hMenu, SC_CLOSE, MF_ENABLED);
Abhimanyu K VatsaPosted May 2, 2011, 9:24 AM
http://stackoverflow.com/questions/3211518/remove-closex-button-from-wpf-window
http://stackoverflow.com/questions/743906/how-to-hide-close-button-in-wpf-window
RamanaPosted May 2, 2011, 8:43 AM
Abhimanyu K VatsaPosted May 2, 2011, 8:37 AM