VSTO custom task pane - c#

I am trying to create a custom task pane in Excel 2016.As far as I see, there is same code all site to create it.But common problem is taskpane is unvisible. The code doesn't give any error.
help please

In AddIns:
private TaskWaterMark taskPaneControl1;
private Microsoft.Office.Tools.CustomTaskPane taskPaneValue;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
taskPaneControl1 = new TaskWaterMark();
taskPaneValue = this.CustomTaskPanes.Add(taskPaneControl1, "MyCustomTaskPane");
taskPaneValue.Visible = true;
//taskPaneValue.DockPosition = Office.MsoCTPDockPosition.msoCTPDockPositionFloating;
//taskPaneValue.Height = 500;
//taskPaneValue.Width = 500;
//taskPaneValue.DockPosition = Office.MsoCTPDockPosition.msoCTPDockPositionRight;
//taskPaneValue.Width = 300;
this.Application.WorkbookActivate += new Excel.AppEvents_WorkbookActivateEventHandler(Application_WorkbookActivate);
taskPaneValue.VisibleChanged +=new EventHandler(taskPaneValue_VisibleChanged);
}
private void Application_WorkbookActivate(Microsoft.Office.Interop.Excel.Workbook wb)
{
}
public void taskPaneValue_VisibleChanged(object sender, System.EventArgs e)
{
Globals.Ribbons.Ribbon1.toggleButton2.Checked = taskPaneValue.Visible;
}
public Microsoft.Office.Tools.CustomTaskPane TaskPane
{
get { return taskPaneValue;}
}
In Rıbbon:
private void toggleButton2_Click(object sender, RibbonControlEventArgs e)
{
Globals.ThisAddIn.TaskPane.Visible = ((RibbonToggleButton)sender).Checked;
}

Did you try to debug the code? Do you get any exceptions in the code?
The fact is that Office may disable the add-in automatically if it fires an exception at startup. Here is what you may see in MSDN:
Microsoft Office applications can disable VSTO Add-ins that behave unexpectedly. If an application does not load your VSTO Add-in when you try to debug it, the application might have hard disabled or soft disabled your VSTO Add-in.
Hard disabling can occur when an VSTO Add-in causes the application to close unexpectedly. It might also occur on your development computer if you stop the debugger while the Startup event handler in your VSTO Add-in is executing.
Soft disabling can occur when a VSTO Add-in produces an error that does not cause the application to unexpectedly close. For example, an application might soft disable a VSTO Add-in if it throws an unhandled exception while the Startup event handler is executing.
When you re-enable a soft-disabled VSTO Add-in, the application immediately attempts to load the VSTO Add-in. If the problem that initially caused the application to soft disable the VSTO Add-in has not been fixed, the application will soft disable the VSTO Add-in again.
Read more about that in the How to: Re-enable a VSTO Add-in That Has Been Disabled article.

Related

VSTO C# in Powerpoint: WindowSelectionChange Event

I am new to VSTO and C# and have a question regarding events.
I'm trying to fire an event when the user selects something within PowerPoint (e.g. a shape, slide, etc).
I found a working solution for VBA in the Office documentation here and some more info for a Word selection handler here, however I'm clueless on how and where to add it in my ThisAddIn.cs context.
I'm currently working from a fresh C# PowerPoint VSTO Addin
Any pointers into the right direction are highly welcome. Thanks!
Found this and it works:
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
this.Application.WindowSelectionChange += Application_WindowSelectionChange;
}
private void Application_WindowSelectionChange(PowerPoint.Selection Sel)
{
//throw new NotImplementedException();
MessageBox.Show("Hello");
}

This addin caused outlook to start slowly

I am developing an Outlook Addin Project using C#.NET 4.5
But After I deploy, Sometimes outlook disables my addin, and shows this message.
"This addin caused outlook to start slowly"" I dont know whats wrong with my addin.
This has only a few codes, and ThisAddIn_Startup is empty in this project.
Here is the code...
public partial class ThisAddIn
{
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
{
return new Ribbon1();
}
#region VSTO generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
}
<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" önLoad="Ribbon_Load">
<contextMenus>
<contextMenu idMso="ContextMenuContactItem">
<menuSeparator id="mniMailItemMenuSeparator" />
<button id="customButton"
label="Call using Software" insertBeforeQ="Copy"
imageMso="Call"
önAction="OnMyButtonClick" />
</contextMenu>
<contextMenu idMso="ContextMenuMailItem">
<menuSeparator id="mailmenusep1" />
<button id="mailbutton" insertBeforeQ="Copy"
label="Call using Software"
imageMso="Call"
önAction="MailItemCallNumbers" />
</contextMenu>
</contextMenus>
</customUI>
Starting with Outlook 2013, Microsoft introduced new performance criteria for add-ins. For more information see http://msdn.microsoft.com/en-us/library/office/jj228679.aspx#ol15WhatsNew_AddinDisabling
In your case, Outlook is loading the .Net framework and is considering the cost as part of your add-in. Native COM add-ins tend to load faster than .Net add-ins.
As the article points out (in the section "System Administrator control over add-ins", there is a Group Policy setting that allows you to specify which add-ins are always enabled, always disabled (blocked), or configurable by the user.
Though not recommended, as Outlook does when "Always enable this Add-In" is selected (as described here), you could directly add your add-in to the following registry key.
HKCU\Software\Microsoft\Office\15.0\Outlook\Resiliency\DoNotDisableAddinList
For improving the performance of VTSO based add-in, see Performance Improvements Coming Soon to a Service Pack Near You
For changing when an add-in is loaded, see Delay-loading the CLR in Office Add-ins.
This can happen on an empty project if you build your add-in in debug mode and attach the debugger to it. The added time required to load all the symbols files into the debugger when it get attached might take longer than Outlook is expecting for a "stable" plugin to initialize.
You shouldn't worry about this unless it happens in a release build with no debugger attached. During development, you can simply tell outlook to never disable your plugin.
Try delay loading of your addins. Try setting Load Behaviour to 8 or 9 for On-Demand loading.
Check this for more
http://blogs.msdn.com/b/andreww/archive/2008/04/19/delay-loading-the-clr-in-office-add-ins.aspx
I know this is an older post, but I found something online that helped me out.
Your post says "This addin caused outlook to start slowly I dont know whats wrong with my addin." I found if you add a particular Environment Variable that more robust messages will appear.
From the Start menu, right click Computer -> Properties -> Advanced System Settings -> click the Environment Variables button. Click New button under the bottom pane called System Variables and add the following. Enter 'VSTO_SUPPRESSDISPLAYALERTS' with a variable value of 0 (Zero). Should look like this.
Now re-open the application that your add-in was attached too, for me it was Outlook. When the add-in starts the error message should now appear with a Details button, click and read through the Exception. For me it looked like this.

Excel VSTO Add-In: Cannot reactivate Excel after MessageBox.Show("Test");

I am implementing a VSTO Excel Add-In which displays some modal dialogs. These dialogs are not shown as own windows in the windows taskbar. But under certain circumstances these dialogs are not are vanishing from the top of Excel and cannot got back by using the task bar!
The whole story (reproducable with Windows XP - 7, Excel 2007 - 2010):
I do open Excel and create two or more new workbooks
I do show a modal dialog, let's say via "MessageBox.Show" I open "notepad" and maximize its window
I try to reactivate one of the excel workbook windows via the windows
taskbar
I expect: Excel will come up with my modal MessageBox to
appear on top
The actual result is: Neither the MessageBox nor any of the Excel workbooks comes up, when you click a workbook item in the windows taskbar!
Why???
I can reactivate Excel via Ctrl + Tab. Then my modal dialog / MessageBox is correctly on the top. It's easy to reproduce if you have Visual Studio and Excel. Please help!
Greets, Jörg
Code-Sample:
Just create an empty Visual C# / Office / 2010 / Office 2010 Add-In
Replace the content of "ThisAddIn.cs" by the following code:
-
namespace ExcelAddIn6
{
public partial class ThisAddIn
{
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
NativeWindow excelWindowThatIsTheOwner = null;
try
{
//Get excel main window to set owner (however does not help anyway)
excelWindowThatIsTheOwner = new NativeWindow();
excelWindowThatIsTheOwner.AssignHandle(new IntPtr(Globals.ThisAddIn.Application.Hwnd));
//Create two more workbooks to have more than one...
Globals.ThisAddIn.Application.Workbooks.Add();
Globals.ThisAddIn.Application.Workbooks.Add();
Globals.ThisAddIn.Application.WindowState = Excel.XlWindowState.xlMaximized;
//Show modal dialog (here: a message box, but )
MessageBox.Show(owner: excelWindowThatIsTheOwner,
text: "I am a modal MessageBox.\nNow bring another application to the foreground and then try to bring excel back via the windows taskbar...");
//Problem stays the same for modal forms
var myForm = new Form();
myForm.ShowInTaskbar = false;
myForm.ShowDialog(excelWindowThatIsTheOwner);
}
finally
{
//Cleanup
if (excelWindowThatIsTheOwner != null) excelWindowThatIsTheOwner.ReleaseHandle();
}
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
#region VSTO generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
}

How can you add a Custom Panel in a Visio 2013 add-in?

Recently I wrote an outlook add-in which has a ribbon.xml file for an extra ribbon, context menu's, etc. I also added an extra panel docked on the right of my window.
Now I've begun some research as on how to create add-ins for Visio. The ribbon.xml is practically the same, so that's not a problem at all. However, I can't seem to find any way to add a custom panel when a Visio document is opened.
So far I have this in Visio to know if a document is opened/created/changed:
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
MessageBox.Show("Visio Add-In V1");
Globals.ThisAddIn.Application.DocumentChanged += new Visio.EApplication_DocumentChangedEventHandler(docChanged);
Globals.ThisAddIn.Application.DocumentOpened += new Visio.EApplication_DocumentOpenedEventHandler(docChanged);
Globals.ThisAddIn.Application.DocumentCreated += new Visio.EApplication_DocumentCreatedEventHandler(docChanged);
}
private void docChanged(Visio.Document doc)
{
MessageBox.Show("Document loaded");
}
In outlook I would do this to add a custom panel (simplified):
MyPanel ctrl = new MyPanel();
Microsoft.Office.Tools.CustomTaskPane ctp = Globals.ThisAddIn.CustomTaskPanes.Add(ctrl, title);
ctp.Visible = true;
ctp.Width = 300;
ctp.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionRight;
Now how would I be able to do this in a Visio 2013 Add-In?
Edit:
Unfortunately this makes me think it's not possible:
http://msdn.microsoft.com/en-us/library/vstudio/bf08984t.aspx
Edit2:
The following answer should work: Are Task Panes Available in Visio VSTO?
However I can't seem to find a way to get a docked panel on my main window. Here is what I tried:
Globals.ThisAddIn.Application.Windows.Add("testpanel", VisWindowStates.visWSDockedLeft, VisWinTypes.visStencilAddon, null, null, null, 300);
This adds the window as if it were a new drawing...
Edit3:
Visio throws a COM exception on this saying I have an invalid window type.
Application.Windows.Add("testpanel", VisWindowStates.visWSDockedRight, VisWinTypes.visAnchorBarAddon, null, null, 300);
You can use Anchor Bars in Visio, not Task Panes
If you download the Visio SDK and look in the Codes Samples Library, you will find Anchor Bar Usage under User Interface.
For completeness, you may wish to review this MSDN article Windows.Add Method (Visio) - http://msdn.microsoft.com/en-us/library/office/ff767674.aspx

CustomTaskPane wont close completely

When I close a CustomTaskPane and change the worksheet, it seems that a pane wasn't removed completely. And the Worksheet area of size of CustomTaskPane becomes inactive.
Here is how I am doing in code:
ctp.Visible = false;
And in PaneVisibleChanged event:
private void PaneVisibleChanged(object sender, EventArgs e)
{
CustomTaskPane pane = (CustomTaskPane)sender;
if (!pane.Visible)
{
pane.Control.Dispose();
CustomTaskPanes.Remove(pane);
}
}
Observation: It happens when I have two CustomTaskPanes side by side and I am closing one.
I'm facing a similar issue with a custom task pane not disposing correctly in VSTO Excel 2010. The code I'm using that tries to fix the issue is simple:
var taskbar = Globals.ThisWorkbook.Application.CommandBars["Task Pane"];
taskbar.Reset();
The Visible event of the side panel does not seem to work ok for me. I usually show or hide the task pane like this:
Globals.ThisWorkbook.Application.CommandBars["Task Pane"].Visible = false;

Categories