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;
Related
I'm new to Visual Studio & C#, still trying to learn.
I have two forms Form 1 and 2
Click on a label in form 1 will go to form 2.
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
linkLabel1.LinkBehavior = System.Windows.Forms.LinkBehavior.NeverUnderline;
(new Form2()).Show(); this.Hide();
}
However for form 2, the color of the label text changes to light grey text even though the ForeColor properties is black.
Am i missing out something here? Thank you.
Update: Seems like the text in form 2 appears but it is disabled (greyed out). Is there a way to enable the label? Not sure why is it even disabled in the first place.
Managed to resolve my issue.
Error msg: forms that are not enabled cannot be displayed as a modal dialog box
The form was not enabled, so i had to enable it
oneDriveForm.Enabled = true;
Full code below
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
linkLabel1.LinkBehavior = System.Windows.Forms.LinkBehavior.NeverUnderline;
SubOneDriveForm oneDriveForm = new SubOneDriveForm();
oneDriveForm.Enabled = true;
oneDriveForm.ShowDialog();
}
Reference:
Button enabling not working correctly
I created my own Excel Addin and after clicking the button displays a Custom Task Pane on right. Everything is fine but when I run this addin in Excel 2013. This displays Custom Task Panes with slide it open.For my Addin Flashes disappear and appear. It looks like a problem with the display.
Is there any solution? It looks very, very wrong.
PS. I'm sure they do not Set Custom Task Panes instance twice.
Display and hide performed using xxxxxxx.Visible = true / false;
Slide to close is Ok.
-------ThisAddIn.cs
_calcTaskPaneControl = new UI.CalcTaskPane();
_calcTaskPaneValue = this.CustomTaskPanes.Add(_calcTaskPaneControl, Common.CommonFunctions.GetLocalizeText("ThisAddIn_CalcTaskPaneTitle"));
_calcTaskPaneValue.VisibleChanged += new EventHandler(CalcTaskPaneValue_VisibleChanged);
--------MainRibbon.cs
Globals.ThisAddIn.CalcTaskPane.Visible = true;
I've noticed the same with Excel 2013. Whenever you set the visibility or the width, Excel 2013 reloads the taskpane. I had to updated all places to check if the CustomTaskPane not already is visible or invisible before setting it. So when your CTP is visible and you set Visible to True again, it will reload the taskpane. Excel 2010 doesn't do this.
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
}
I have a project that I'm doing with
Microsoft VSTO (office 2013 excel)
I have certain things that make calls that take maybe 10 seconds to come back.
Ideally I would like to display an progress bar or some status... After a lot of searching I found an article that is titled:
How do I create a splash screen window for the VSTO applications?
http://www.datazx.cn/Fv7p5a/xw/oa2v/2q7xs6/mcccjfti-988m-f8r8-8d44-bstb4rfsi4xm23rsdfd.html
So I started creating this code in a form, but then I realize that I need to call it up within my methods and really attach events etc...
The article says to
"display a modal form on a background thread" What is the best way to do this?
I find it easier to use modal less form on main thread and so far haven't seen any problem with modal less approach. Something like code below
var splashWindow = new SplashWindow();
splashWindow.Show();
splashWindow.SetMessage("Starting please wait...");
DoSomeWork(splashWindow);
splashWindow.Close();
Following you will see a way I programmed a Splash Screen for Excel-VSTO in C#. My Excel file is enabled for macros (.xlsm). These are the steps:
Create your splash screen. Let's assume the name of the form is SplashScreen.
Go to the code of the object ThisWorkbook.cs
Check the code looks like:
public partial class ThisWorkbook
{
SplashScreen SC = new SplashScreen();
private async void ThisWorkbook_Startup(object sender, System.EventArgs e)
{
SC.Show();
await Task.Delay(3500);
SC.Close();
more code...
}
}
It is important that you notice that I added the word async to the subroutine.
private void ThisWorkbook_Startup(object sender, System.EventArgs e)
I hope this is very useful.
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