embed a button into an excel chart - c#

Roughly speaking, I want to create a child class from Excel Chart to add the following features into the child:
add a button to the visual appearance of the chart (the button should have a fixed position relatively to the chart - so if I move chart, the button moves as well). Actually, it doesn't have to be exactly button - it may be anything else which allows clicking on it (or do any other action) and do some activities after the click.
add some additional properties to the chart (these properties doesn't appear vizually but they influence the representation of the time-series). Maybe there is a standard way to customize the set of the properties of Excel Chart?
I don't know to what extent it is possible. Maybe "child class" is not that good idea to serve such simple needs. Maybe VSTO has something, but I can't find anything suitable in the Internet.
Any help will be very much appreciated!
PS
For the subquestion #2 I've decided to use the field TAG to put there an object with additional parameters.

In answer to your first question it is possible to embed a form-control button or a shape in a chart, and have it keep its position relative to the chart area, by cutting and pasting it onto the chart. Use the OnAction property to assign a procedure to the button.
Recorded code (in Excel) is like this:
Sub Macro1()
ActiveSheet.Buttons.Add(166.5, 48, 48, 32.25).Select
Selection.OnAction = ActiveWorkbook.Name & "!TestMacro"
Selection.Cut
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Paste
Selection.ShapeRange.IncrementLeft 10
Selection.ShapeRange.IncrementTop 30
End Sub
It may be possibly to do this programmatically without cutting and pasting, perhaps by adding to the ChartObject's ShapeRange, but I haven't explored this.
I do not know to what extent you can directly subclass an Excel Chart (if at all) and suspect that you might just create a wrapper class for it in C#.

Related

Is there an option in chart.js to hide values in the graph legend

I've picked up a project from a former colleague but know nothing about javascript and/or chart.js, I'm trying to learn.
I've been asked to part of the graph/legend - red ring in the image.
The thing is the chartjs json string/structure is split into separate variables which make it pretty hard to follow - and also give code samples. I've tried changing the "options" string, i.e. options: {legend: {display:false }}, but it's still displaying.
Is the part marked red actually part of the legend or is it something else on the chart
Image showing what I need to hide
That isn't the legend. Somewhere in the options there is a property xAxes. Here your collegue has defined multiple new axes. These are the ones you see. If you remove them and remove the xAxisId from the datasets you will get what you want

how can I lock shapes in PowerPoint?

I'm working on a Add-in for PowerPoint 2010 (C#) and I want to prevent the end-user to move or edit all the shapes that I have programmatically created.
I have already sought in the framework but I think it's not allowed programmaticaly. Has anyone already encountered this kind of limitations and could help me to find a solution?
I know that some people create their add-in thanks to C++ because there are a lot of limitations in office.
I have found two solutions :
The first is to catch all events from the "commandBars.OnUpdate" like this great sample code : http://code.msdn.microsoft.com/CSExcelNewEventForShapes-0e26b1f2#content
Then you can impose the position/the color or everything you want to your shape.
The second one is more "brutal" > unselect immediately the shape. When you catch all the events from the "CommandBars.OnUpdate" do this :
To see which shape is selected :
var selectedShape = this.Application.ActiveWindow.Selection.ShapeRange[1]
In all my shapes, I have set a tag with an ID. I have just to check that there are an ID in the tags of the selectedShape and if this is the case :
this.Application.ActiveWindow.Selection.Unselect();
Then I show a messageBox to warn the user to do not select this kind of shape.
I don't like this solution but it's the only one that I have found and it works.
I believe this is not possible. A way of achieving this to a certain extent (people can work around it if they figure out how to select the shapes below) is by making a transparent rectangle the size of the canvas and binding a custom event to that (like you described in your comment). The transparent rectangle is overlaying the shapes you created so people can no longer access the shapes that way. Of course if they are capable of figuring out how to select the shapes they can move them anyway...
Alternatively, to make people not do stuff like that (you only stop the inexperienced) you can also set them up as master slides.
Only 'real' solution for people not doing that? Images .. but then they can move the image too!

Is it possible tracking shape changes in powerpoint addin?

Currently on my project of ppt addin, I want to know if it is possible tracking shape changes made by the user:
Text Box A Move to ( 210, 100)
Text Box B Change Font to Calibri
Text Box B Change Style to Underline
Delete Text Box C
Add Image A
Resize Image A to 320x240
...
What I know for PPT 2013 there's an AfterShapeSizeChange event so you can know after re-sizing, but I need more than that, which is all possible changes did by the user.
After trying to find out through browsing, here's some possibilities:
Create my own log tracking using SelectionChanged event, but this gonna be tricky if user press CTRL+Z or CTRL+Y
look through undo/redo stack (people says it's impossible...)
Do you need to actually track changes or do you need to be able to detect that a change has been made? Ie, that a given shape isn't exactly the same as it was in the original.
If the latter, how about this:
Write a routine that "touches" each shape in the presentation and adds tags to it, one tag for each property that you want to be able to detect changes to.
Then all you'd need to do is look at each shape's tags and see if the properties stored there match the current properties of the shape.
For example, to tag the shapes:
For each oSl in ActivePresentation.Slides
For each oSh in oSl.Shapes
oSh.Tags.Add "Left", cstr(oSh.Left)
oSh.Tags.Add "Top", cstr(oSh.Top)
Next
Next
I've the same problem.
Let me say, I think the best solution would be serialize the shape to XML (shape state) and save it in the shape it-self. In this way next time you access the shape you can check the current state with the serialized one.
It's possible to save XML in a shape, but you cannot serialize the COM shape in "one command", you have implement your own serialization looking to all shapes properties (!!!! to much I think).
What I did as work-around is: every time the user puts a shape (let's say ShapeA) in the slide a create a shape copy in a specific master page (ShapeA_state1), the new shape holds my ShapeA state. Then I save a reference to that ShapeA_state1 into the ShapeA. In this way when a second time the app access the ShapeA, the app can check if the state is changed looking to the referenced ShapeA_state1. When that happens, ShapeA.1 is updated to ShapeA_edited
Another way to solve this is to add a thread to your program that monitors Application.ActivePresentation.Saved - if it gets set to false you know a change has been made and can look at the selected object or slide - of course you need to add a layer to reset the Saved flag - and pass it back before saving.
I've had no success with accessing the undo information.
I have had good success with adding a mouse hook and intercepting button presses before PPT does - perfect for intercepting things like the PlaySlideShow button before Application_SlideShowBegin and the Next/Prev slides during playback before Application_SlideShowNext* events.
When working out where the button positions you wish to intercept are keep in mind things such as PresenterMode and DPI scale changes.

Update/Replace Shapes in visio diagram programmatically (C#)

I would like to programmatically(C#) update/replace all shapes of a given visio flowchart(*.vsd). The diagram layout remain the same(all connections, coordinates etc. are the same), but the master-shapes should be different(from different stencil).
Any examples, suggestions and ideas are highly appreciated.
Thanks for your suggestions! The source-diagram has many protected shapes that are grouped(+multiple subshapes), so I guess it will be better, if I take all the information for a given source-shape, and then drop a new master from the target-stencil and set these properties. Next, I would take the next Shape and do the same. I would create a new Visio document, since Iā€™m not sure, whether the source Page-ShapeSheet is not customized someway. But I don't know how to do basic steps programmatically in C# e.g.
how to create new vsd file within C# (maybe
application.Documents.AddEx(ā€œā€))
must I then open this document with application.Document.OpenEx, or the document is already open/active
must I create a new Page within this document
-ā€¦
In this post: "save and close visio documents visual basic macro
" similar steps explained, but in VBA and not in C#.
I'd suggest just using Visio 2013, which has that function out of the box.
However, that's probably not going to work for you. I've taken two different routes in the past, depending on what differences there were between the original and the replacement shape.
One way to do this is, to copy as many attributes as you can between the shapes, and duplicate the glues and everything. So to do this, you just copy the width, height, pins, etc.., and then step through all the glues in the original shape, and move the glues to the new shape.
The other way, which is a bit cleaner, in my opinion, is wholesale copying all the geometry sections from the original into the destination shape. This makes it so you don't have to worry about glues and formatting and things, and are just copying over the graphics that make up the shape.
If you have a grouped shape with multiple subshapes, it's probably going to be easier to drop a new master out, but if it's just a simple graphic-type shape, copying the geometry is probably better.
One thing to be aware of with the "copy the geometries" method is, you have to make sure any user cells or controls which are precedent to any geometry cells in the new shape also exist in the original shape. Visio's Cell class tells you the precedents for a cell, so this is easy enough to do.
Hope that helps.
I think you can extract some information from these two links and play with it:
Visio shape - get X,Y position
http://msdn.microsoft.com/en-us/library/cc160747.aspx

Implementing MS Access style 'relationships' GUI

I have no idea what the correct name for this UI style is. In MS Access the 'relationships' tool shows the db tables as little movable boxes that can be linked with lines. It's the same with Visio and a few audio apps - boxes that are movable, containing lines of text that can be joined together in a meaningful way.
How could I create a similar thing in .NET using Visual Studio 2008 and C#? I've never created my own controls before.
Here's an image of the sort of thing I mean: Click for example
You'll need two main custom controls: the main view and the table control.
The table control is responsible for drawing itself with all of its columns and ensuring that the item can scroll if need be. It is also responsible for providing an x/y co-ordinate for a specified row header. This is so that the relationship lines can match up to the correct row.
The main view is responsible for accepting a list of table objects (stored in a custom table object), creating the same number of table controls and arranging them in a specified order. It is also responsible for drawing the lines between the table controls.
All in all, this is not trivial. You'll want to override the OnPaint() method of both these controls to do all this custom drawing. Do some research on the GDI+ graphics routines to find out what methods you can use to draw this. You'll probably be using these objects/methods most often:
Pen
SolidBrush
LinearGradientBrush
DrawRectangle()
FillRectangle()
DrawString()
DrawImage()
DrawLine()
DrawPath()
You'll also need to trap all kinds of mouse events to enable moving the controls around. This can be done by overriding methods such as OnMouseDown or OnMouseMove.
Good luck.
The diagram you are trying to draw is an ERD or Database design. What you might also be looking for is a Class Diagram.
What you are trying to do is pretty complex.
Here are some links that might help. These are all open source type UML tools that do diagraming.
http://imar.spaanjaars.com/501/automatically-generating-class-diagrams-from-a-type-using-reflection
http://www.codebydesign.com/
http://sourceforge.net/projects/use-case-maker/
http://projects.gnome.org/dia/
http://www.monouml.org/doku.php?id=documentation

Categories

Resources