Listing 23.1 contains the class that creates the certificate. The class is named CertificatesVB (or CertificatesCS for the C# version) and is consumed from the Default.aspx.vb code. You can use this class in just about any ASP.NET program. The CertificatesVB class has exactly five member variables that aren't associated with a property. These variables are private class members and can't be accessed externally. They can be seen at the top of Listing 23.1. The first two variables determine the width and height of the certificate itself. Note, though, that the user interface objects, such as the DropDownList and TextBox objects, add to the size of the screen in which users create a certificate. You can easily change these programmatically for a different certificate size. But they aren't the kind of thing that you'll want users changing. These two values can wreak havoc if they are way too big or way too small because the certificate elements won't fit on the certificate very well. Two variables determine whether or not the lower left image and the lower right image are raised above the bottom of the certificate. This positioning is necessary if text is drawn in the lower left or lower right corner of the certificate. You wouldn't want to draw images on top of text; so if text exists, two variables will contain additional offsets with which the lower left and lower right images can be drawn so that the text won't be drawn on the text. These two variables are m_nLeftImageBottom and m_nRightImageBottom. The last of the non-property member variables is a Bitmap object named m_objImage. It will contain the Bitmap object into which all of the drawing will be performed. Then, once all of the drawing operations have been completed, the Bitmap object will be saved to disk as an image file. A property named BackgroundTile is associated with a member variable named m_strBackgroundTile. The variable is a string and contains the name of the image file that will be used to tile the background of the certificate. The CertificatesVB class has the expectation that all the background tile images will be in a directory within the current directory named BackgroundTiles. The directory that the ASPNET-Solutions Web site uses has 54 background tiles. You can download these tiles from the Web site from the Chapter 23 page at http://www.ASPNET-Solutions.com/Chapter_23.htm. You can download thousands of additional background tiles from the Internet. Almost any image will work, but the ones that work best are tiles that fit together seamlessly. Four properties are all related. These properties contain the file name for images that can be placed in the four corners of the certificate. Each image is a GIF image with a transparent background. That means that instead of an entire rectangle being pasted on top of the certificate, only the non-background color will be drawn. The demo application on the ASPNET-Solutions Web site has 53 corner images from which users can select. The CertificatesVB class expects the images to be contained in a directory under its directory named Corner Images. You can download the 53 images from the Chapter 23 page on the ASPNET-Solutions Web site. The four member variables that contain the file names are m_strUL Image, m_strURImage, m_strBLImage, and m_strBRImage. The corresponding properties for these variables with which the calling code can get and set them are UpperLeftImage, UpperRightImage, BottomLeftImage, and BottomRightImage. Two properties determine where the certificate image is saved and what its file name will be. These are respectively the Path and Filename properties. Their associated member variables are respectively m_strPath and m_strFilename. The next three properties in Listing 23.1 contain the text that will be drawn in the certificate. The MainText property sets the m_strMainText member variable and contains the text that will be drawn in the middle of the certificate. The LeftText and RightText properties set the m_strLeftText and m_strRightText member variables. These strings are drawn at the bottom left and bottom right corners of the certificate. Their purpose would be for displaying who issued the certificate, what date it was awarded, or a special note. An array of colors allows users to store colors as integers. The integers are indexes into the array of colors (named m_Colors), which in turn is used to draw text into the certificate's Bitmap object. The last three properties in Listing 23.1 are integer values that contain indexes into the color array. The MainTextColor property sets the m_nMainTextColor integer variable and determines the color with which the main text is drawn. The LeftTextColor and RightTextColor properties do the same for the text that might be drawn in the lower left and lower right corners of the certificate. Listing 23.1 The Certificate's Member Variables and PropertiesDim m_nWidth As Integer = 650 Dim m_nHeight As Integer = 350 Dim m_nLeftImageBottom As Integer = 0 Dim m_nRightImageBottom As Integer = 0 Dim m_objImage As Bitmap = Nothing Dim m_strBackgroundTile As String = "LBlueBack.gif" Public Property BackgroundTile() As String Get Return m_strBackgroundTile End Get Set(ByVal Value As String) m_strBackgroundTile = Value End Set End Property Dim m_strULImage As String = "" Public Property UpperLeftImage() As String Get Return m_strULImage End Get Set(ByVal Value As String) m_strULImage = Value End Set End Property Dim m_strURImage As String = "" Public Property UpperRightImage() As String Get Return m_strURImage End Get Set(ByVal Value As String) m_strURImage = Value End Set End Property Dim m_strBLImage As String = "" Public Property BottomLeftImage() As String Get Return m_strBLImage End Get Set(ByVal Value As String) m_strBLImage = Value End Set End Property Dim m_strBRImage As String = "" Public Property BottomRightImage() As String Get Return m_strBRImage End Get Set(ByVal Value As String) m_strBRImage = Value End Set End Property Dim m_strFilename As String = "Tmp.jpg" Public Property Filename() As String Get Return m_strFilename End Get Set(ByVal Value As String) m_strFilename = Value End Set End Property Dim m_strPath As String = "" Public Property Path() As String Get Return m_strPath End Get Set(ByVal Value As String) m_strPath = Value End Set End Property Dim m_strMainText As String = "" Public Property MainText() As String Get Return m_strMainText End Get Set(ByVal Value As String) m_strMainText = Value End Set End Property Dim m_strLeftText As String = "" Public Property LeftText() As String Get Return m_strLeftText End Get Set(ByVal Value As String) m_strLeftText = Value End Set End Property Dim m_strRightText As String = "" Public Property RightText() As String Get Return m_strRightText End Get Set(ByVal Value As String) m_strRightText = Value End Set End Property Dim m_Colors() As Color = {Color.Black, Color.White, _ Color.Blue, Color.Green, Color.Red, Color.Yellow} Dim m_nMainTextColor As Integer = 0 Public Property MainTextColor() As Integer Get Return m_nMainTextColor End Get Set(ByVal Value As Integer) m_nMainTextColor = Value End Set End Property Dim m_nLeftTextColor As Integer = 0 Public Property LeftTextColor() As Integer Get Return m_nLeftTextColor End Get Set(ByVal Value As Integer) m_nLeftTextColor = Value End Set End Property Dim m_nRightTextColor As Integer = 0 Public Property RightTextColor() As Integer Get Return m_nRightTextColor End Get Set(ByVal Value As Integer) m_nRightTextColor = Value End Set End Property |