- txtbxlib_project.zip
- txtbxlib project
- HTML
- ctxtbx.ReadMe.htm
- ctxtbx.ReadMe.pdf
- ctxtbx.ReadMe_files
- image002.jpg
- image004.jpg
- image005.jpg
- image007.jpg
- image009.jpg
- image011.jpg
- SomeClient
- txtbxlib
|
<html>
<head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<title>TextBox ctxtbx </title>
<style>
<!--
-->
</style>
</head>
<body link=blue vlink=purple>
<div>
<h1>Subject: Extending
user control and IDE Toolbox</h1>
<p><b>Category: </b>Events/Delegates, Windows Form,
Custom Controls, IDE Toolbox Extension</p>
<p><b> </b></p>
<p><b>Author: </b>Norman Fung</p>
<p><b>Contact: </b><a
href="mailto:norman.fung@applied-algorithms.com">norman.fung@applied-algorithms.com</a>,
<a href="mailto:norman_lm_fung@hotmail.com">norman_lm_fung@hotmail.com</a>� </span></p>
<p><b>Submission date: </b>12 August 2003</p>
<p> </p>
<p><b> </b></p>
<p><b>I.
</b><b>WHAT IS IT:</b></p>
<p>1.
"ctxtbx"
inherits from TextBox (<i>System.Windows.Forms</i>). Control extension: If
length of character string in textbox (ctxtbx.Text.Length) exceeds a specified
number of characters (ctxt.FlashLength), textbox starts flashing, indicating to
user that entered character string is invalid (too long).</p>
<p> </p>
<p>2.
Purpose
of this project is to demonstrate the following:</p>
<p>a.To
extend user control via delegates and events.</p>
<p>b.To add
custom control to Toolbox. Access control property via Property Browser.</p>
<p> </p>
<p><b>3.
</b>The
control is packaged in one single dll. It can be consumed by any .NET/WIN32
client. </p>
<p><b> </b></p>
<p>4.
<b>APPLICATION
NOTE </b>provides
necessary information to deploy this module to C#/VB.NET client. Please be
reminded that RAD tools is only available to C#/VB.NET. If you intend to
consume this package in a managed C++/COM/WIN32 client, procedures provided in
APPLICATION NOTES does not readily apply.</p>
<p> </p>
<p>5.
<b>P</b>erquisite to this tutorial: C#/VB.NET,
Windows Forms, UEM (unified events modeling). A good understanding of the
following subjects would help, but not entirely necessary: assemblies, strong
names, PPK, GAC.</p>
<p> </p>
<p> </p>
<p><b>II. </b><b>APPLICATION
NOTE:</b></p>
<p> </p>
<p>����������� 1.
To install module into GAC (Global Assembly Cache):</p>
<p>a.
Key
file: <b><i>txtbxlib.snk </i></b>(This step is already done. Key file is in
your solution folder.) Key file is generated with sn.exe, and it�s referenced
by �AssemblyInfo.cs�. For those of you who�re not entirely familiar with the
procedure, read up on the following topic: GAC, sn.exe, assembly, strong name.</p>
<p> </p>
<p>For your
information, here�s the command prompt entry: </p>
<p>�sn
-k txtbxlib.snk�</p>
<p> </p>
<p>b.
Visual
Studio.NET command prompt: gacutil -i txtbxlib.dll (You need to do this
yourself.)</p>
<p>����������������������� �� (/photo/Fig 5)</p>
<p> </p>
<p>2.
To add
control to <b><i>Toolbox</i></b>:</p>
<ol start=2 type=1>
<ol start=1 type=a>
<li>right click anywhere on Toolbox. (/photos/Fig
1)</li>
</ol>
</ol>
<p> </p>
<p> </p>
<p><img border=0 width=492 height=369
src="./ctxtbx.ReadMe_files/image002.jpg"></span></p>
<p> </p>
<ol start=2 type=1>
<ol start=2 type=a>
<li>Select �Customize Toolbox� (/Photo/Fig 1,2)</li>
</ol>
</ol>
<p> </p>
<ol start=2 type=1>
<ol start=3 type=a>
<li>Select �.NET Framework components� (/photo/Fig
2)</li>
</ol>
</ol>
<p> </p>
<p> </p>
<p><img border=0 width=528 height=397
src="./ctxtbx.ReadMe_files/image004.jpg"></span></p>
<p> </p>
<ol start=2 type=1>
<ol start=4 type=a>
<li>Browse, and select txtbxlib.dll (/photo/Fig 3)</li>
</ol>
</ol>
<p> </p>
<p><img border=0 width=504 height=379
src="./ctxtbx.ReadMe_files/image005.jpg"></span></p>
<p> </p>
<p> </p>
<p>To use the control
in your Windows Form, just drag from Toolbox and drop it onto your form.
(/photo/Fig 1)</p>
<p>����������� </p>
<p>3.
Three
control properties:</p>
<p> </p>
<p>a.
<b><i>ctxtbx.FlashLength</i></b>(Length of character string in textbox to trigger
flashing. Default: 10)</p>
<p>b.
<b><i>ctxtbx.flashColor</i></b> (Flash color. Default:
System.Drawing.Color.Red)</p>
<p>c.
<b><i>ctxtbx.flashfreq
</i></b>(Flash
frequency. Default: 1)</p>
<p> </p>
<p>You can access these
properties from "Properties Browser"�
(/photo/Fig 4), or in class <b><i>ctxtbx </i></b>constructor. Now,
select the editbox and pay attention to browser and Fig 6 (class hierarchy).
Please note that <i>ONLY <b>properties </b></i>can be found under �Properties
Browser� � other class attributes do not get displayed here. </p>
<p> </p>
<p><img border=0 width=528 height=396
src="./ctxtbx.ReadMe_files/image007.jpg"></span></p>
<p> </p>
<p>That�s all for client implementation, just drag the
control from the Toolbox and drop it on your Windows form. A sample application
is included in the package for demonstration purpose (SomeClient). Before you
run the executable, make sure:</p>
<ol start=3 type=1>
<ol start=1 type=a>
<li>control assembly (txtbxlib.dll) has been
installed into GAC.</li>
<li>Toolbox references to txtbxlib.dll</li>
</ol>
</ol>
<p> </p>
<p>Now, that�s the easy way � which implies that there�s
an alternative: Just cut and paste the control class �<b><i>ctxtbx� </i></b>from
library source file <b><i>�txtbxlib.cs�</i></b>, and instantiate <b><i>ctxtbx </i></b>in
your Windows Form�s constructor. Be sure to include the following namespace: <i>System.Threading</i>,
<i>System.Drawing</i>, <i>System.Windows</i>, <i>System.Windows.Forms</i>, <i>System</i>.</p>
<p> </p>
<p> </p>
<p> </p>
<p><b>III. </b><b>Architecture
and implementation:</b></p>
<p> </p>
<p>Everything
in <b>c<i>txtbx </i></b>is packaged in one single dll (Managed C# class
library): <b><i>txtbxlib.dll</i></b></p>
<p>Please note that references to System.Drawing,
System.Windows.Forms was added to the solution.</p>
<p> </p>
<p><img border=0 width=256 height=220
src="./ctxtbx.ReadMe_files/image009.jpg"></span></p>
<p> </p>
<p> </p>
<p>At the top of the package is <b><i>txtbxlib
</i></b>namespace. <b><i>ctxtbx </i></b>class is the one and only one class
implemented in the dll.</p>
<p> </p>
<p><img border=0 width=254 height=359
src="./ctxtbx.ReadMe_files/image011.jpg"></span></p>
<p> </p>
<p>Perhaps the easiest way to explain
the code is to trace the sequence of events which is fired when user click the
textbox. So, here it is:</p>
<p> </p>
<p>1.
User enter into textbox.</p>
<p> </p>
<p>2.
<b><i>OnKeyDown
</i></b>is triggered.</p>
<p> </p>
<p>protectedoverridevoid OnKeyDown(KeyEventArgs e)</p>
<p>����������������������� {</p>
<p>����������������������������������� CheckLength();</p>
<p>����������������������������������� base.OnKeyDown(e);</p>
<p>}</p>
<p> </p>
<p>The method will invoke CheckLength</p>
<p> </p>
<p>3.
<b><i>CheckLength
</i></b>is triggered.
The method checks the length of the character string in ctxtbx everytime user
enter into the textbox. If length of character string <b><i>ctxtbx.Length </i></b>exceeds
<b><i>ctxtbx.FlashLength</i></b>, event <b><i>OutOfRangeEvent </i></b>is fired.
If not, nothing happens. </p>
<p> </p>
<p>publicdelegateint OutOfRangeDelegate(int
num);</p>
<p>publicevent
OutOfRangeDelegate OutOfRangeEvent;</p>
<p> </p>
<p>Now, the association between
OutOfRangeEvent and its handlers can be found in the constructors:</p>
<p> </p>
<p>OutOfRangeDelegate
d1 = new OutOfRangeDelegate(this.OnOutOfRange_1);</p>
<p>OutOfRangeDelegate
d2 = new OutOfRangeDelegate(this.OnOutOfRange_2);</p>
<p>����������������������������������������������� </p>
<p>this.OutOfRangeEvent
+= d1; </p>
<p>this.OutOfRangeEvent += d2;</p>
<p> </p>
<p>The above code snippets maps handler <b><i>OnOutOfRange_1
</i></b>and <b><i>OnOutOfRange_2 </i></b>to <b><i>OutofRangeEvent </i></b>through
delegate <b><i>OutOfRangeDelegate</i></b>.</p>
<p> </p>
<p> </p>
<p>4.
Event
handlers invoked.</p>
<p> </p>
<p>4-a. <b><i>OnOutOfRange_1</i></b></p>
<p>This method spins up a thread to execute FlashIt(..) � which
gives you the flashing.</p>
<p> </p>
<p>4-b<b><i>
OnOutOfRange_2</i></b></p>
<p>This method changed the border style from <b>fixed-single </b>to
<b>fixed-3D</b>. </p>
<p> </p>
<p>5.
Let�s
say the user realize that she made a mistake and truncate the character strings
to less than <b><i>ctxtbx.FlashLength</i></b>. Once again,<b><i> OnKeyDown </i></b>is
triggered. </p>
<p> </p>
<p> </p>
<p>6. CheckLength
is triggered in turn. But, this time, since the number of characters in the textbox
<b><i>ctxtbx.Length </i></b>is less than <b><i>ctxtbx.FlashLength</i></b>, <b><i>OutOfRangeEvent
</i></b>is NOT fired and the thread that executes the flashing (m_FlashThread)
is aborted.</p>
<p> </p>
<p>That�s
pretty much it. </p>
<p> </p>
<p> </p>
<p> </p>
<p><b>IV.
</b><b>Project Package: </b>ctxtbx.zip</p>
<p> </p>
<p><b>1. </b><b>ctxtbx
Control</b></p>
<p>Project
Type: C# class library</p>
<p>Project
Name: txtbxlib</p>
<p>Binary:
txtbxlib.dll (Release folder)</p>
<p>Key file:
txtbxlib.snk</p>
<p> </p>
<p><b>2. </b><b>SomeClient</b></p>
<p>Project
Type: C# Windows Application</p>
<p>Binary:
SomeClient.exe (You need to install control assembly to GAC first!)</p>
</div>
</body>
</html>
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.