By using the below code I created a Shape in Visual studio Tools for Office
private void Sheet01_Startup(object sender, System.EventArgs e)
{
this.Shapes.AddShape(Office.MsoAutoShapeType.msoShapeActionButtonCustom, 160, 461, 109, 20);
}
I want do some thing when I click on the shape.
Please help me to write events for this.
VSTO doesn't provide anythig for that.
If you are talking about an Excel add-in, the Shape class doesn't provide any event for that. I bielive you may find the SelectionChange event of the Worksheet class helpful. It is fired when the selection changes on a worksheet. So, you can check out the select object on sheet.
Related
I have a screen with over fifty buttons on it. I want to be able to detect which button was clicked and then proceed to a different screen with data based on what button was clicked. However, I can't seem to detect a click from the mouse without the use of a specific button name. I would like to avoid using 50+ OnEvent() functions if possible. If not, I will just write them all.
Any advice would be greatly appreciated on how I can go about doing this, thanks!
You are using C#? C++? VB.NET? Java?
C# Code:
Here is an Event as Example:
private void button1_Click(object sender, EventArgs e)
{
if (sender is Button)
{
MessageBox.Show((sender as Button).Name);
}
}
You can replace the MessageBox, it is just meant to make it a proof by example.
I have about 20 local reports on a report viewer inside a winform. They all load fine/take parameters etc. But whenever I press the backspace button the report disappears and I am presented with this message: Back call without drillthrough report.
I am not using any drillthrough reports or sub reports and I haven't implemented anything to do with the backspace button in my code. (I'm using VB)
Is there a way to stop this from happening?
I had this same issue as well. I do not have any subreports or drillthroughs configured. I was able to capture the backspace and handle it there. The keydown event handler below belongs to the form and not to the reportviewer control itself. I'm on VS2010.
private void rptViewer_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Back)
{
e.Handled = true;
}
}
I hope this is a simple question, I'm new at Mono, and I'm having trouble getting to grips with GTK#'s bindings.
Essentially, I want to be able to programmatically change attributes against objects like labels, buttons and lists added in by the designer in MonoDevelop.
I know this can be done by instantiating a new instance of say, a button as such:
Button button1 = new Button("Text for button here");
However, say button1 was already created, how would I grab button1 to make changes to it?
Sorry if this all comes across a little thick, I'm still getting the hang of OOP.
Thanks!
This is actually easy enough, now I've sat and worked it out:
protected void OnButton1Clicked (object sender, EventArgs e)
{
Button theButton = (Button)button1;
theButton.Label = "New label text!!";
}
I am just starting with Excel 2010 Add-in with VSTO and is quickly stumped by an exception generated by this code:
public void DoIt()
{
Excel.Range selectedRange = Application.Selection as Excel.Range;
if (selectedRange == null)
{
System.Windows.Forms.MessageBox.Show("Nothing selected");
}
else if(selectedRange.Cells.Count > 0)
{
selectedRange[1, 1].Value = "=2+3"; // exception on this line.
selectedRange[selectedRange.Rows.Count, selectedRange.Columns.Count].Value = "Birthday";
}
}
The exception can be reproduced by first clicking on a single cell in the worksheet, then click the formula bar and then run the above function (I call it via a Ribbon button).
Could anyone advise what is happening and how to handle this exception? Thanks you.
The exception is because you can't run code while in formula-editing mode. You also can't do quite a few other things. For example, click into the formula bar and click Ctrl-N, which normally opens a new workbook. Nothing happens.
I think you need to just Catch the exception and exit the Sub, which will mimic normal Excel operation.
Ideally you'd want to disable the button, just like most Excel ribbon buttons are when in formula-editing mode. I don't know if that's possible though.
The medical company I work for has a EMR system setup to keep digital copies of patient files so they are searchable as well as quick to access. A new request has come through to be able to save e-mail to the EMR system, however it does not display .msg files very nicely. It does display files nicely as .htm, so was hoping i could figure out a way to save email messages to a specific folder in a .htm format with the user just hitting a single button.
Should i be looking at making an add-in using vs 2010 to do this simple task? Or would there be a better way to do this?
I've explored making an Add-In breifly over the past few days using command bars but have hit numerous problems with adding the menu item to mail items, as well as losing event handlers or having them fire quite a few times, so i'm wondering if i'm barking up the wrong tree.
Edit: Looking at ribbon bar customization as well, may have to upgrade some users that are still using 2003, but seems like it might be the better option than command bars going forward.
Ribbon bar was the best path i found, however i had trouble finding a great how-to for the start-to-finish project, so i'll make a small write up here.
To add a button to the ribbon for only existing mail messages including a image for the button.
Using VS 2010
New project, Office, select "Outlook 2007 add in", enter a name for your project.
To your newly created project, Add a new item "Ribbon (XML)" name it however you want, i'll call it CustomRibbon
open your newly created CustomRibbon.xml file and change the tab node to have the following
<tab idMso="TabReadMessage">
<group insertBeforeMso="GroupActions" id="CustomGroup" label="GroupNameThatShowsInOutlook">
<button id="btnCustomButton"
label = "Text For The Custom Button"
supertip="tip for the button hover"
onAction ="ButtonClicked"
size="large"
getImage="GetCustomButtonImage" />
</group>
</tab>
This then has 2 callback functions to the CustomRibbon.cs file, one called GetCustomButtonImage, the other ButtonClicked.
open CustomRibbon.cs to fill this in, in the Ribbon Callbacks region add the following
public void ButtonClicked(Office.IRibbonControl Control)
{
//Do work here
}
also add the following in the same section
public stdole.IPictureDisp GetCustomButtonImage(Office.IRibbonControl control)
{
System.Drawing.Image myImage;
myImage = OutlookAddIn.Properties.Resources.ImageName;
return AxHostConverter.ImageToPictureDisp(myImage);
}
this will then show there is a class missing, we'll get to that shortly, but first we are going to add in the last part we need in CustomRibbon.cs. In the IRibbonExtensibility Members region, in GetCustomUI change the existing code
public string GetCustomUI(string ribbonID)
{
if (ribbonID == "Microsoft.Outlook.Mail.Read")
{
return GetResourceText("OutlookAddIn.CustomRibbon.xml");
}
else
{
return "";
}
}
Add a new class to your project call it AxHostConverter, add add this to the top
using System.Windows.Forms;
using System.Drawing;
Then change the class to have the following code
class AxHostConverter : AxHost
{
private AxHostConverter() : base("") { }
static public stdole.IPictureDisp ImageToPictureDisp(Image image)
{
return (stdole.IPictureDisp)GetIPictureDispFromPicture(image);
}
static public Image PictureDispToImage(stdole.IPictureDisp pictureDisp)
{
return GetPictureFromIPicture(pictureDisp);
}
}
Add your image for your button to the project, and change the GetCustomButtonImage function to use that resource. I used a PNG and had good luck with transparencies displaying well.
And finally, all that should be left is to add the following to ThisAddIn.cs
protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
{
return new CustomRibbon();
}
Add whatever code you are wanting to ButtonClicked and you are set.
Deploy using Clickonce and installation is fairly straightforward.