19: Building Custom Controls Implementing the Basics in .NET

Creation QR Code JIS X 0510 in .NET 19: Building Custom Controls Implementing the Basics
19: Building Custom Controls Implementing the Basics
Draw QR Code ISO/IEC18004 In .NET
Using Barcode creator for ASP.NET Control to generate, create QR Code ISO/IEC18004 image in ASP.NET applications.
First, you will need to create a class that inherits from the UserControl class To do this, create a new Windows Control Library project in Visual Studio 2005 We will name our project InfoPathControlLibrary (This le is included with the samples for this chapter) Once you complete the New Project Wizard, Visual Studio will create the basic template code for the new user control Before continuing, let s rename our user control class to
Barcode Creation In Visual Studio .NET
Using Barcode drawer for ASP.NET Control to generate, create barcode image in ASP.NET applications.
InfoPathMaskedTextBox
Encoding QR Code In Visual C#
Using Barcode generator for VS .NET Control to generate, create QR Code image in .NET framework applications.
Next, let s add the MaskedTextBox control to the design surface of our user control by dragging and dropping it from the Visual Studio Toolbox And, just for purposes of this demonstration, let s open the properties for the control and set the Mask property to Social security number At this point, if we build the control, it is usable in applications that natively support NET controls but not in InfoPath To make this control work in InfoPath, we rst need to make it look like a normal ActiveX control by using COM interop This isn t nearly as dif cult as it sounds We just need to add a few attributes to the class to specify that the control is visible to COM, has a GUID, and has a class interface Listing 192 shows the InfoPathMaskedTextBox class after we added the attributes needed to make the class appear to InfoPath as an ActiveX control Note that the ClassInterface attribute must be set to ClassInterfaceTypeAutoDual for the control to work within InfoPath Also, the CLSID speci ed in the Guid attribute was obtained by running the guidgenexe tool, which is included with Visual Studio 2005
Generating QR Code In .NET
Using Barcode creation for VS .NET Control to generate, create QR Code image in .NET framework applications.
Listing 192: InfoPathMaskedTextBox Class After Adding COM Interop Attributes
Drawing QR Code JIS X 0510 In VB.NET
Using Barcode generation for VS .NET Control to generate, create QR Code JIS X 0510 image in Visual Studio .NET applications.
[ComVisible(true)] [Guid("F24E3AC4-3987-4a62-9DDC-AB56CE896301")] [ClassInterface(ClassInterfaceTypeAutoDual)] public partial class InfoPathMaskedTextBox : UserControl { }
Barcode Generation In .NET Framework
Using Barcode generation for ASP.NET Control to generate, create bar code image in ASP.NET applications.
Next, once you ve added the necessary attributes to make your class look like an ActiveX control, you will want to expose a couple of properties to InfoPath namely, the Value and Enabled properties Let s create an interface called IInfoPathMaskedTextBox that will de ne these properties
Generating GS1 128 In VS .NET
Using Barcode generator for ASP.NET Control to generate, create EAN / UCC - 14 image in ASP.NET applications.
Building Custom Controls for InfoPath Using ActiveX
Bar Code Drawer In VS .NET
Using Barcode drawer for ASP.NET Control to generate, create barcode image in ASP.NET applications.
(Listing 193) There are a couple of things to note about this code First, we have to use the InterfaceType attribute and set it to ComInterfaceTypeInterfaceIsIDispatch to expose this interface through COM This attribute speci es that this interface supports IDispatch, which is necessary when using the control in InfoPath Next, since this is a dispatch interface, we have to specify dispatch IDs for the two properties it supports using the DispId attribute The IDs we use are de ned in the InfoPathMaskedTextBox class DispidValue and DispidEnabled These IDs can be de ned as any value you like, but, as you ll see later, if your binding property is Value, you should set DispidValue to 0
Creating UPC A In Visual Studio .NET
Using Barcode encoder for ASP.NET Control to generate, create UPC A image in ASP.NET applications.
Listing 193: IInfoPathMaskedTextBox Interface
UPC - 13 Generation In .NET
Using Barcode generation for ASP.NET Control to generate, create EAN-13 image in ASP.NET applications.
[InterfaceType(ComInterfaceTypeInterfaceIsIDispatch)] public interface IInfoPathMaskedTextBox { [DispId(InfoPathMaskedTextBoxDispidValue)] string Value { get; set; } [DispId(InfoPathMaskedTextBoxDispidEnabled)] bool Enabled { get; set; } }
Making USS Code 128 In VS .NET
Using Barcode encoder for ASP.NET Control to generate, create Code 128 Code Set B image in ASP.NET applications.
The IInfoPathMaskedTextBox control interface is then added to the inheritance list for the InfoPathMaskedTextBox class The Value property is implemented to get and set the value of the nested masked text box object The Enabled property simply enables or disables the masked text box control Listing 194 shows the code to implement the IInfoPathMaskedTextBox interface
Print Code11 In .NET
Using Barcode drawer for ASP.NET Control to generate, create Code11 image in ASP.NET applications.
Listing 194: Implementation of the IInfoPathMaskedTextBox Interface Methods
Encoding USS Code 128 In Java
Using Barcode encoder for Java Control to generate, create Code128 image in Java applications.
public string Value { get { return maskedTextBox1Text; } set { maskedTextBox1Text = value; } } public new bool Enabled { get { return maskedTextBox1Enabled; } set { maskedTextBox1Enabled = value; } }
Generate Barcode In Java
Using Barcode drawer for Java Control to generate, create barcode image in Java applications.
19: Building Custom Controls
Scan GS1 - 13 In VS .NET
Using Barcode decoder for VS .NET Control to read, scan read, scan image in .NET applications.
Now, if you build your control, it will act as an ActiveX control and will expose the Value and Enabled properties, which can be used in InfoPath However, the control still won t work in InfoPath until we implement the IObjectSafety interface
Bar Code Creator In Visual C#.NET
Using Barcode creation for Visual Studio .NET Control to generate, create bar code image in VS .NET applications.
Implementing IObjectSafety
Code 39 Extended Encoder In Java
Using Barcode drawer for Java Control to generate, create Code 39 image in Java applications.
The IObjectSafety interface is a standard COM interface that has no equivalent in the NET world However, that doesn t mean that you can t use it in your managed code controls To use it, you simply need to de ne the interface, as you would any other interface, and then expose it to COM applications using COM interop The code in Listing 195 shows the de nition of the IObjectSafety interface in C# (The original de nition of this interface is in the objsafeidl le in the Platform SDK The CLSID speci ed in the Guid attribute comes from this de nition) Since this is a COM interface, we ve speci ed the typical ComImport, Guid, and InterfaceType attributes on the interface declaration, as well as the PreserveSig attribute on the method declarations in order to preserve the return value of each method
Barcode Recognizer In .NET
Using Barcode recognizer for .NET framework Control to read, scan read, scan image in VS .NET applications.
Encoding Bar Code In Visual Basic .NET
Using Barcode generator for .NET Control to generate, create bar code image in .NET applications.