208: OnSwitchView Event Handler in .NET framework

Make QR Code 2d barcode in .NET framework 208: OnSwitchView Event Handler
Listing 208: OnSwitchView Event Handler
Quick Response Code Creator In .NET Framework
Using Barcode generator for ASP.NET Control to generate, create QR Code ISO/IEC18004 image in ASP.NET applications.
void Connect_OnSwitchView(DocEvent pEvent) { CommandBarButton copyButton = GetButton("Copy"); copyButtonEnabled = true; CommandBarButton pasteButton = GetButton("Paste"); pasteButtonEnabled = (_copiedNode != null); }
Bar Code Printer In .NET Framework
Using Barcode maker for ASP.NET Control to generate, create bar code image in ASP.NET applications.
20: Add-ins
Paint QR Code In C#.NET
Using Barcode generation for .NET framework Control to generate, create Denso QR Bar Code image in VS .NET applications.
Copy and Paste Button Event Handlers So far, we ve talked about what happens when the COM add-in is loaded and how to initialize the toolbar and copy and paste buttons Now that we ve added the user interface for the add-in, what s next Well, obviously, we want something to happen when the user clicks one of the buttons Listing 209 shows the code for the click event handler for the copy button Remember that we hooked up this event handler (as well as the handler for the paste button) when we initialized the buttons in OnStartupComplete
QR Code Generation In .NET Framework
Using Barcode generation for VS .NET Control to generate, create Denso QR Bar Code image in .NET applications.
Listing 209: Copy Button Event Handler and EnabledAllPasteButtons Method
Generating QR Code 2d Barcode In VB.NET
Using Barcode printer for .NET Control to generate, create QR-Code image in .NET applications.
public void OnCopyClick(CommandBarButton Ctrl, ref bool CancelDefault) { try { XDocument document = _applicationObjectActiveWindowXDocument; IXMLDOMNode rootNode = documentDOMselectSingleNode( "*[not(self::processing-instruction())]"); _copiedNode = rootNodecloneNode(true /*deep*/); EnableAllPasteButtons(); } catch (Exception e) { MessageBoxShow(eMessage); } } private void EnableAllPasteButtons() { Windows windows = _applicationObjectWindows; int numWindows = windowsCount; for (int i = 0; i < numWindows; i++) { Window window = windows[i]; CommandBar toolbar = ((CommandBars)windowCommandBars)[ToolbarName]; CommandBarButton pasteButton = (CommandBarButton)toolbarFindControl( MsoControlTypemsoControlButton, MissingValue, PasteButtonTag, true, false); pasteButtonEnabled = true; } }
Barcode Drawer In VS .NET
Using Barcode generation for ASP.NET Control to generate, create barcode image in ASP.NET applications.
Building a COM Add-in for InfoPath
Printing Data Matrix In .NET
Using Barcode creation for ASP.NET Control to generate, create Data Matrix 2d barcode image in ASP.NET applications.
Let s look at this event handler in detail When the copy button is clicked, the OnCopyClick method is called This method receives a copy of the CommandBarButton that was clicked, as well as a bool parameter that can be set to cancel the default action, if any When the copy button is clicked, we want to store the root node of the document in the _copiedNode member variable so that we can paste it into other documents later Therefore, we must rst get the root node from the DOM property of the current document The current document is stored in the XDocument property on the Window object Obviously, we want to access that document from the current window, so we get it from the ActiveWindow property of the _applicationObject object Once we have the document, we have to get the root node To get the root node, we call the selectSingleNode method of the DOM, passing an XPath that will return the rst node that is not a processing-instruction node (Of course, this will return only the rst node, which may or may not be the root, depending on the complexity of the schema For the purposes of this sample, we re assuming that the rst node that is not a processing instruction is the root) Once we have the root, we clone it and store it in _copiedNode for later We re almost nished Remember that the OnSwitchView method is where we enable the buttons We always enable the copy button, but we enable the paste button only if _copiedNode is not null Therefore, the rst time that OnSwitchView is called after the COM add-in is loaded, the paste button will be disabled So, when the copy button is clicked, we want to enable the paste button To do so, we simply call EnableAllPasteButtons But wait why is this called EnableAllPasteButtons Don t we have only one paste button That s true, but remember that there could be multiple InfoPath windows open at any given time So, when the copy button is pressed, we want to enable the paste button in each of the opened windows To do that, EnableAllPasteButtons loops through all the windows in the Windows collection, gets the Form Utilities toolbar, nds the paste button, and enables it It s that simple So, now you see how the add-in copies the data in the form However, what do we do when we want to paste the data into a new form When the paste button is pressed, the OnPasteClick event handler is called, as shown
Make Code-39 In .NET Framework
Using Barcode maker for ASP.NET Control to generate, create USS Code 39 image in ASP.NET applications.
Drawing Code 128B In Visual Studio .NET
Using Barcode encoder for ASP.NET Control to generate, create Code 128A image in ASP.NET applications.
Generate EAN / UCC - 13 In VS .NET
Using Barcode creator for ASP.NET Control to generate, create UCC - 12 image in ASP.NET applications.
Barcode Scanner In .NET
Using Barcode scanner for Visual Studio .NET Control to read, scan read, scan image in Visual Studio .NET applications.
Data Matrix 2d Barcode Creator In .NET
Using Barcode creator for .NET Control to generate, create Data Matrix image in Visual Studio .NET applications.
Draw Bar Code In Visual Basic .NET
Using Barcode generation for Visual Studio .NET Control to generate, create bar code image in .NET applications.
ECC200 Encoder In Java
Using Barcode drawer for Java Control to generate, create Data Matrix ECC200 image in Java applications.