CreateNodeXLControl() { m_oNodeXLWithAxesControl = new NodeXLWithAxesControl(); m_oNodeXLWithAxesControl.XAxis.Label = "This is the x-axis"; m_oNodeXLWithAxesControl.YAxis.Label = "This is the y-axis"; m_oNodeXLControl = m_oNodeXLWithAxesControl.NodeXLControl; m_oNodeXLControl.SelectionChanged += new System.EventHandler(this.m_oNodeXLControl_SelectionChanged); m_oNodeXLControl.VertexClick += new Microsoft.NodeXL.Core.VertexEventHandler( this.m_oNodeXLControl_VertexClick); m_oNodeXLControl.VertexDoubleClick += new Microsoft.NodeXL.Core.VertexEventHandler( this.m_oNodeXLControl_VertexDoubleClick); m_oNodeXLControl.VertexMouseHover += new Microsoft.NodeXL.Core.VertexEventHandler( this.m_oNodeXLControl_VertexMouseHover); m_oNodeXLControl.VertexMouseLeave += new EventHandler(this.m_oNodeXLControl_VertexMouseLeave); m_oNodeXLControl.VerticesMoved += new Microsoft.NodeXL.Visualization.Wpf.VerticesMovedEventHandler( this.m_oNodeXLControl_VerticesMoved); m_oNodeXLControl.PreviewVertexToolTipShown += new VertexToolTipShownEventHandler( this.m_oNodeXLControl_PreviewVertexToolTipShown); m_oNodeXLControl.GraphMouseDown += new Microsoft.NodeXL.Visualization.Wpf.GraphMouseButtonEventHandler( this.m_oNodeXLControl_GraphMouseDown); m_oNodeXLControl.GraphMouseUp += new Microsoft.NodeXL.Visualization.Wpf.GraphMouseButtonEventHandler( this.m_oNodeXLControl_GraphMouseUp); m_oNodeXLControl.GraphZoomChanged += new System.EventHandler(this.m_oNodeXLControl_GraphZoomChanged); m_oNodeXLControl.LayingOutGraph += new System.EventHandler(this.m_oNodeXLControl_LayingOutGraph); m_oNodeXLControl.GraphLaidOut += new AsyncCompletedEventHandler(this.m_oNodeXLControl_GraphLaidOut); ehElementHost.Child = m_oNodeXLWithAxesControl; }
//************************************************************************* // Constructor: GraphImageCenterer() // /// <summary> /// Initializes a new instance of the <see cref="GraphImageCenterer" /> /// class. /// </summary> /// /// <param name="nodeXLControl"> /// The control for which a graph image will be created. /// </param> //************************************************************************* public GraphImageCenterer( NodeXLControl nodeXLControl ) { Debug.Assert(nodeXLControl != null); m_oNodeXLControl = nodeXLControl; m_dOriginalTranslateTransformForRenderX = m_dOriginalTranslateTransformForRenderY = m_dOriginalScaleTransformForRenderCenterX = m_dOriginalScaleTransformForRenderCenterY = Double.MinValue; AssertValid(); }
//************************************************************************* // Method: SaveGraphImageFile() // /// <summary> /// Save an image of the graph to a file. /// </summary> /// /// <param name="oNodeXLControl"> /// The control that displays the graph. /// </param> /// /// <param name="sWorkbookFilePath"> /// Path to the workbook file. Sample: "C:\Workbooks\TheWorkbook.xlsx". /// </param> /// /// <remarks> /// The settings stored in the AutomatedGraphImageUserSettings class are /// used to save the image. /// </remarks> //************************************************************************* private static void SaveGraphImageFile( NodeXLControl oNodeXLControl, String sWorkbookFilePath ) { Debug.Assert(oNodeXLControl != null); Debug.Assert( !String.IsNullOrEmpty(sWorkbookFilePath) ); AutomatedGraphImageUserSettings oAutomatedGraphImageUserSettings = new AutomatedGraphImageUserSettings(); Size oImageSizePx = oAutomatedGraphImageUserSettings.ImageSizePx; Bitmap oBitmapCopy = oNodeXLControl.CopyGraphToBitmap( oImageSizePx.Width, oImageSizePx.Height); ImageFormat eImageFormat = oAutomatedGraphImageUserSettings.ImageFormat; String sImageFilePath = Path.ChangeExtension( sWorkbookFilePath, SaveableImageFormats.GetFileExtension(eImageFormat) ); try { oBitmapCopy.Save(sImageFilePath, eImageFormat); } catch (System.Runtime.InteropServices.ExternalException) { // When an image file already exists and is read-only, an // ExternalException is thrown. // // Note that this method is called from the // ThisWorkbook.GraphLaidOut event handler, so this exception can't // be handled by a TaskAutomator.AutomateThisWorkbook() exception // handler. FormUtil.ShowWarning( String.Format( "The image file \"{0}\" couldn't be saved. Does a read-only" + " file with the same name already exist?" , sImageFilePath ) ); } finally { oBitmapCopy.Dispose(); } }
//************************************************************************* // Constructor: GraphLaidOutEventArgs() // /// <summary> /// Initializes a new instance of the <see cref="GraphLaidOutEventArgs" /> /// class. /// </summary> /// /// <param name="graphRectangle"> /// The rectange the graph was drawn within. /// </param> /// /// <param name="edgeIDDictionary"> /// Dictionary that maps edge IDs stored in the edge worksheet to edge /// objects in the graph. /// </param> /// /// <param name="vertexIDDictionary"> /// Dictionary that maps vertex IDs stored in the vertex worksheet to /// vertex objects in the graph. /// </param> /// /// <param name="nodeXLControl"> /// The control in which the graph was laid out. /// </param> //************************************************************************* public GraphLaidOutEventArgs( Rectangle graphRectangle, Dictionary<Int32, IIdentityProvider> edgeIDDictionary, Dictionary<Int32, IIdentityProvider> vertexIDDictionary, NodeXLControl nodeXLControl ) { m_oGraphRectangle = graphRectangle; m_oEdgeIDDictionary = edgeIDDictionary; m_oVertexIDDictionary = vertexIDDictionary; m_oNodeXLControl = nodeXLControl; AssertValid(); }
protected void CreateNodeXLControl() { m_oNodeXLWithAxesControl = new NodeXLWithAxesControl(); m_oNodeXLWithAxesControl.XAxis.Label = "This is the x-axis"; m_oNodeXLWithAxesControl.YAxis.Label = "This is the y-axis"; m_oNodeXLControl = m_oNodeXLWithAxesControl.NodeXLControl; m_oNodeXLControl.SelectionChanged += new System.EventHandler(this.m_oNodeXLControl_SelectionChanged); m_oNodeXLControl.VertexClick += new Microsoft.NodeXL.Core.VertexEventHandler( this.m_oNodeXLControl_VertexClick); m_oNodeXLControl.VertexDoubleClick += new Microsoft.NodeXL.Core.VertexEventHandler( this.m_oNodeXLControl_VertexDoubleClick); m_oNodeXLControl.VertexMouseHover += new Microsoft.NodeXL.Core.VertexEventHandler( this.m_oNodeXLControl_VertexMouseHover); m_oNodeXLControl.VertexMouseLeave += new EventHandler(this.m_oNodeXLControl_VertexMouseLeave); m_oNodeXLControl.VerticesMoved += new Microsoft.NodeXL.Visualization.Wpf.VerticesMovedEventHandler( this.m_oNodeXLControl_VerticesMoved); m_oNodeXLControl.PreviewVertexToolTipShown += new VertexToolTipShownEventHandler( this.m_oNodeXLControl_PreviewVertexToolTipShown); m_oNodeXLControl.GraphMouseDown += new Microsoft.NodeXL.Visualization.Wpf.GraphMouseButtonEventHandler( this.m_oNodeXLControl_GraphMouseDown); m_oNodeXLControl.GraphMouseUp += new Microsoft.NodeXL.Visualization.Wpf.GraphMouseButtonEventHandler( this.m_oNodeXLControl_GraphMouseUp); m_oNodeXLControl.GraphZoomChanged += new System.EventHandler(this.m_oNodeXLControl_GraphZoomChanged); m_oNodeXLControl.LayingOutGraph += new System.EventHandler(this.m_oNodeXLControl_LayingOutGraph); m_oNodeXLControl.GraphLaidOut += new AsyncCompletedEventHandler(this.m_oNodeXLControl_GraphLaidOut); ehElementHost.Child = m_oNodeXLWithAxesControl; }
//************************************************************************* // Method: TransferToNodeXLControl() // /// <summary> /// Transfers the settings to a <see cref="NodeXLControl" />. /// </summary> /// /// <param name="nodeXLControl"> /// Control to transfer the settings to. /// </param> //************************************************************************* public void TransferToNodeXLControl( NodeXLControl nodeXLControl ) { Debug.Assert(nodeXLControl != null); AssertValid(); TransferToGraphDrawer(nodeXLControl.GraphDrawer); nodeXLControl.MouseAlsoSelectsIncidentEdges = this.AutoSelect; }