I'm trying to write a plugin for Outlook 2013 that processes content of emails.
So far, I've created an Outlook Addin-project in Visual Studio. Furthermore, I created a ribbon button, with
RibbonType = Microsoft.Outlook.Mail.Read
to show the button only when an email is read.
Is it possible get access to the email in order to e.g. show the subject or the content (consisting of plain text)?
private void button1_Click(object sender, Ribbon ControlEventArgs e)
{
System.Windows.Forms.MessageBox.Show( ... );
}
Use the RibbonControlEventArgs.Control property to get to the RiibbonControl object. You can then use the IRibbonControl.Context property and cast it to the Inspector object (for inspectors) or Explorer (for the Explorer buttons). Once you have the Inspector object, use the Inspector.CurrentItem property.
Thanks Dmitry for your help!
private void button1_Click(object sender, RibbonControlEventArgs e)
{
var mailItem = ((Inspector) e.Control.Context).CurrentItem;
MessageBox.Show(mailItem.Subject);
MessageBox.Show(mailItem.Body);
}
Related
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");
}
I need to disable Microsoft Word start screen programatically using C# in Visual Studio. I don't want to do it manually like this .
Anyone can help ?
I found a good workaround for it. It is simply to open a new blank document on startup
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
if (Application.Documents.Count == 0)
{
Application.Documents.Add();
}
}
I have a question : I need to show pdf documents without askink what to open to the user. It needs to be matched with a unique id. Let's say I have a product_ID=55435, and I need to open the 55435.pdf by automatically in a windows form.
Thank you !
I suggest you follow the steps below:
(1) You can add ActiveX controls provided by Adobe to the toolbox.
Method: Right click on the blank of the toolbox=>choose items=>COM Components=>check AdobePDF Reader=>OK
As the picture shows:
(2) You can drag the Adobe PDF Reader control to the form, create a button button1, and add button events.
The button event code is as follows:
private void button1_Click(object sender, EventArgs e)
{
string filename =; // Example: filename = #"F:\SoftWare\PdfFile\55435.pdf";
axAcroPDF1.LoadFile(filename);
}
Running result:
I have a web browser control in C# that it's design mode is on. I use it to make a (WYSIWYG) HTML editor. I want to insert a photo on this without UI, when user wants to insert image I show to him/her a window that shows on it some known name for user. Then with search (s)he find her/his photo and add it to control.
this is my open image form:
Photos are in database and user only know them with names. I upload all of them in a folder and show above list to user and user selects a picture. I want to add image by it's location in hard disk and allow user to set its alignment .
How I can do this ?
Adding a new element to a document is very logical. The first step is to create the node (element) you wish to append, the next is to find where you wish to append it within the document, and the final step is to actually do the appending.
I write an Example for you:
private void Form1_Load_1(object sender, EventArgs e)
{
webBrowser1.DocumentText = "<html><body></img></body></html>";
}
private void insert_image_btn_Click(object sender, EventArgs e)
{
HtmlElement userimage = webBrowser1.Document.CreateElement("img");
userimage.SetAttribute("src", "image location");
userimage.Id = "imageid";
webBrowser1.Document.Body.AppendChild(userimage);
}
private void btn_set_aliign_Click(object sender, EventArgs e)
{
webBrowser1.Document.GetElementById("imageid").SetAttribute("float", "right");
}
I am creating a small Visual Studio 2010 extension in C# which uses the IWpfTextViewCreationListener and TextViewCreated to capture when a new TextView is opened in the VS environment. The problem I am having is that this method only fires when a new window is opened via the VS Solution Explorer window, and not fired when VS already contains opened windows when started, and switching window tabs. I have tried looking for something like TextViewChanged, but could not find such method. Is there anyway to capture the new TextView when another tabbed window is selected?
Any help would be greatly appreciated.
This question has also been posted on the MSDN VS Extensibility forum:
VSX 2010 - Alternative to TextViewCreated such as (TextViewChanged)?
Thanks
John
There is no TextViewCreated, but if you register to IWpfTextView.GotAggregateFocus as it is created, you get a hook to every switch between files:
public void TextViewCreated(IWpfTextView textView)
{
textView.GotAggregateFocus += TextViewCameToFocus;
// Do stuff when a new IWpfTextView is created...
}
void TextViewCameToFocus(object sender, EventArgs e)
{
var focusedTextView = (IWpfTextView)sender;
// Do stuff when a specific IWpfTextView comes to focus...
}
You may also want to keep track of the IWpfTextView objects, if you want to be able to link between the fired events to your logic of each textview.