B
Brian McVay
Hi all,
I have created a custom textbox control using VS2003 C# to use in a VB.NET
CF project. In an application test for the desktop the control works just
fine (although some polishing is still needed) , however, for an application
targeted for the Smart Device Application the control does not draw onto the
form at design time.
I have followed the rules inside of the .NET help for compiling the design
time control using the command line compiler and have successfully added it
to the VB.NET toolbar for Smart Device Application in the Designer... but
the designer simply does nothing when the control is selected to add to a
form.
Can anyone provide any feedback on what I am not doing or what I am doing
wrong?
I have provided the control code below for what I currently have.
Thanks in advance.
Brian
-----
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
namespace ABCTextBoxControl
{
/// <summary>
/// Summary description for ABCTextBoxControl.
/// Derived and overridden textbox control to restrict key entry based on
property settings.
/// </summary>
#if NETCFDESIGNTIME
[ToolboxItemFilter("NETCF",ToolboxItemFilterType.Allow),
ToolboxItemFilter("System.CF.Windows.Forms", ToolboxItemFilterType.Custom)]
#endif
public class ABCTextBox : System.Windows.Forms.TextBox
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public ABCTextBox()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
// TODO: Add any initialization after the InitComponent call
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}
#endregion
protected override void OnPaint(PaintEventArgs pe)
{
// TODO: Add custom paint code here
// Calling the base class OnPaint
base.OnPaint(pe);
}
private char[] SpecialCharacters;
public char[] AllowSpecialCharacters
{
set { SpecialCharacters = value;
ArrayIsSortedSet = false;
}
get { return SpecialCharacters;}
}
private bool NumericOnlySet = false;
public bool NumericOnly
{
get {return NumericOnlySet;}
set {NumericOnlySet = value;}
}
private bool AllowNumericSet = true;
public bool AllowNumeric
{
get {return AllowNumericSet;}
set {AllowNumericSet = value;}
}
private bool ArrayIsSortedSet = false;
private bool ArrayIsSorted
{
get {return ArrayIsSortedSet;}
set {ArrayIsSortedSet = value;}
}
private bool RestrictToAllowedSet = false;
public bool RestrictToAllowed
{
get {return RestrictToAllowedSet;}
set {RestrictToAllowedSet = value;}
}
private bool IsNumericOnly ()
{
try
{
string testString = this.Text;
int testParse = Int32.Parse(testString);
return true;
}
catch (Exception e)
{
string holdmessage = e.ToString();
return false;
}
}
private bool myIsNumber (char myChar)
{
return char.IsDigit(myChar);
}
private bool myIsLetter (char myChar)
{
return char.IsLetter(myChar);
}
private bool myIsControl (char myChar)
{
return char.IsControl(myChar);
}
private bool ValidateTextString (string myString)
{
int myLength;
char mySearch;
bool myReturnValue = true;
myLength = myString.Length;
for (int myCounter = 1; myCounter <= myLength; myCounter++)
{
mySearch = Convert.ToChar(myString.Substring(myCounter, 1));
myReturnValue = ValidateThisCharacter(mySearch);
if (myReturnValue == false) break;
}
return myReturnValue;
}
private bool ValidateThisCharacter (char myChar)
{
int intFoundValue;
bool myReturnValue = false;
if (!RestrictToAllowed)
{
if (myIsNumber(myChar))
{
if (AllowNumeric) return true;
}
if (myIsLetter(myChar))
{
if (!NumericOnly) return true;
}
}
if (myIsControl(myChar)) return true;
if (ArrayIsSorted == false)
{
SortArray(SpecialCharacters);
}
intFoundValue = Array.BinarySearch( SpecialCharacters, myChar );
if (intFoundValue >= 0)
{
myReturnValue = Comparer.Equals(myChar,
SpecialCharacters[intFoundValue]);
}
return myReturnValue;
}
public void AddText(string strToAdd) // Add the passed text to this
textbox which could come from numerous sources, methods, or events
{
int intHoldSelectionStart = 0;
intHoldSelectionStart = this.SelectionStart;
try
{
if (this.Text.Length < this.MaxLength)
{
if (ValidateTextString(strToAdd))
{
this.SelectedText = strToAdd;
this.SelectionStart = intHoldSelectionStart + strToAdd.Length;
this.SelectionLength = 0;
this.Focus();
}
}
}
catch (Exception e)
{
string holdmessage = e.ToString(); // TBD
}
}
protected override void OnKeyPress (
System.Windows.Forms.KeyPressEventArgs e )
{
if (!ValidateThisCharacter(e.KeyChar))
{
e.Handled = true;
}
}
private void SortArray (Array myArray)
{
Array.Sort(myArray);
ArrayIsSorted =true;
}
}
}
I have created a custom textbox control using VS2003 C# to use in a VB.NET
CF project. In an application test for the desktop the control works just
fine (although some polishing is still needed) , however, for an application
targeted for the Smart Device Application the control does not draw onto the
form at design time.
I have followed the rules inside of the .NET help for compiling the design
time control using the command line compiler and have successfully added it
to the VB.NET toolbar for Smart Device Application in the Designer... but
the designer simply does nothing when the control is selected to add to a
form.
Can anyone provide any feedback on what I am not doing or what I am doing
wrong?
I have provided the control code below for what I currently have.
Thanks in advance.
Brian
-----
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
namespace ABCTextBoxControl
{
/// <summary>
/// Summary description for ABCTextBoxControl.
/// Derived and overridden textbox control to restrict key entry based on
property settings.
/// </summary>
#if NETCFDESIGNTIME
[ToolboxItemFilter("NETCF",ToolboxItemFilterType.Allow),
ToolboxItemFilter("System.CF.Windows.Forms", ToolboxItemFilterType.Custom)]
#endif
public class ABCTextBox : System.Windows.Forms.TextBox
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public ABCTextBox()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
// TODO: Add any initialization after the InitComponent call
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}
#endregion
protected override void OnPaint(PaintEventArgs pe)
{
// TODO: Add custom paint code here
// Calling the base class OnPaint
base.OnPaint(pe);
}
private char[] SpecialCharacters;
public char[] AllowSpecialCharacters
{
set { SpecialCharacters = value;
ArrayIsSortedSet = false;
}
get { return SpecialCharacters;}
}
private bool NumericOnlySet = false;
public bool NumericOnly
{
get {return NumericOnlySet;}
set {NumericOnlySet = value;}
}
private bool AllowNumericSet = true;
public bool AllowNumeric
{
get {return AllowNumericSet;}
set {AllowNumericSet = value;}
}
private bool ArrayIsSortedSet = false;
private bool ArrayIsSorted
{
get {return ArrayIsSortedSet;}
set {ArrayIsSortedSet = value;}
}
private bool RestrictToAllowedSet = false;
public bool RestrictToAllowed
{
get {return RestrictToAllowedSet;}
set {RestrictToAllowedSet = value;}
}
private bool IsNumericOnly ()
{
try
{
string testString = this.Text;
int testParse = Int32.Parse(testString);
return true;
}
catch (Exception e)
{
string holdmessage = e.ToString();
return false;
}
}
private bool myIsNumber (char myChar)
{
return char.IsDigit(myChar);
}
private bool myIsLetter (char myChar)
{
return char.IsLetter(myChar);
}
private bool myIsControl (char myChar)
{
return char.IsControl(myChar);
}
private bool ValidateTextString (string myString)
{
int myLength;
char mySearch;
bool myReturnValue = true;
myLength = myString.Length;
for (int myCounter = 1; myCounter <= myLength; myCounter++)
{
mySearch = Convert.ToChar(myString.Substring(myCounter, 1));
myReturnValue = ValidateThisCharacter(mySearch);
if (myReturnValue == false) break;
}
return myReturnValue;
}
private bool ValidateThisCharacter (char myChar)
{
int intFoundValue;
bool myReturnValue = false;
if (!RestrictToAllowed)
{
if (myIsNumber(myChar))
{
if (AllowNumeric) return true;
}
if (myIsLetter(myChar))
{
if (!NumericOnly) return true;
}
}
if (myIsControl(myChar)) return true;
if (ArrayIsSorted == false)
{
SortArray(SpecialCharacters);
}
intFoundValue = Array.BinarySearch( SpecialCharacters, myChar );
if (intFoundValue >= 0)
{
myReturnValue = Comparer.Equals(myChar,
SpecialCharacters[intFoundValue]);
}
return myReturnValue;
}
public void AddText(string strToAdd) // Add the passed text to this
textbox which could come from numerous sources, methods, or events
{
int intHoldSelectionStart = 0;
intHoldSelectionStart = this.SelectionStart;
try
{
if (this.Text.Length < this.MaxLength)
{
if (ValidateTextString(strToAdd))
{
this.SelectedText = strToAdd;
this.SelectionStart = intHoldSelectionStart + strToAdd.Length;
this.SelectionLength = 0;
this.Focus();
}
}
}
catch (Exception e)
{
string holdmessage = e.ToString(); // TBD
}
}
protected override void OnKeyPress (
System.Windows.Forms.KeyPressEventArgs e )
{
if (!ValidateThisCharacter(e.KeyChar))
{
e.Handled = true;
}
}
private void SortArray (Array myArray)
{
Array.Sort(myArray);
ArrayIsSorted =true;
}
}
}