I've scanned the threads in this forum and I'm still stumped on a desig
time issue. I'm relatively new to .Net Forms development so I may b
overlooking something simple.
I am trying to create a custom UserControl which contains anothe
custom control that is an extension of TextBox. The custom TextBox an
the parent control I want to place it inside of are both in the sam
assembly (dll). At design time, when I drop the custom TextBox insid
of the custom UserControl VS (2003 .Net 1.1) complains with - "Th
specified cast is not valid." I'm assuming this occurs when th
designer attempts to instantiate the custom TextBox.
I created another custom TextBox that extends TextBox and nothing else
This control does not create a problem for VS when used as describe
above.
Here is the source for the custom TextBox that is causing a problem.
am showing only the public properties, constructor and designer relate
logic. This class also overrides a number of event handlers to handl
keypress validation at runtime. I left this code out - I can't imagin
this logic would present any design time issues.
using System;
using System.Windows.Forms;
using log4net;
using org.twia.meta;
namespace org.twia.forms
{
/// <summary>
/// Supplies the list of modes to be used by the control.
/// </summary>
public enum MaskMode
{
KeyPress,
Leave
}
/// Text Box control for use in a Model View Mediator GUI.
/// </summary>
public class MVMTextBox : System.Windows.Forms.TextBox
ValidatingControl
{
private bool supportsValidation = false;
private ControlBindingType bindingType
ControlBindingType.None;
private static readonly ILog log
LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// validation specific properties
private System.Windows.Forms.ErrorProvider errorProvider = ne
System.Windows.Forms.ErrorProvider();
internal string mask = string.Empty; //regular expression mask
internal bool stripMask = true; //strip mask before validation
internal string text = string.Empty; //actual text with mas
characters removed
internal int selectionStart = 0; //current position in _text
internal string sampleInput = string.Empty; //sample input t
complete regular expression fields for keypress validation
private MaskMode mode = MaskMode.Leave;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
public MVMTextBox()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
// TODO: Add any initialization after the InitializeComponen
call
}
// Properties
/// <summary>
/// Public property used to expose the mask mode of the control.
/// </summary>
public MaskMode Mode
{
get { return mode; }
set { mode = value; }
}
/// <summary>
/// property encapsulating the mask
/// </summary>
public string Mask
{
get { return mask; }
set
{
mask = value != null ? value : "";
renderMaskedText(text);
}
}
/// <summary>
/// property encapsulating actual unmasked text
/// </summary>
public string UnmaskedText
{
get
{
if (stripMask)
return text;
else
return Text;
}
set
{
text = value != null ? value : "";
renderMaskedText(text);
}
}
#region Internal Methods
/// <summary>
/// property encapsulating errorProvider
/// </summary>
internal string Error
{
set
{
errorProvider.SetError(this, value);
}
}
#endregion
/// <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()
{
components = new System.ComponentModel.Container();
}
#endregion
}
}
Could this be an issue with initialization/serialization of the publi
properties? I tried making the properties non-public and still had the
same problem.
If you can point me in the right direction to solving this problem -
thanks!
John

Signature
jdeviney
jokiz - 22 Dec 2005 00:27 GMT
you can easily pinpoint the culprit if you debug the instance that you
drop the customtextbox to the usercontrol designer. have the
customtextbox in another project and have the said project with the
customtextbox code attach to the devenv.exe process where you drop the
said control to the usercontrol designer surface... be sure to break
when an exception is thrown..
> I've scanned the threads in this forum and I'm still stumped on a design
> time issue. I'm relatively new to .Net Forms development so I may be
[quoted text clipped - 173 lines]
> jdeviney's Profile: http://www.hightechtalks.com/m574
> View this thread: http://www.hightechtalks.com/t2314640
jdeviney - 22 Dec 2005 15:10 GMT
I identified the problem. What I did not know is that VS trigger
control events when you place a control on a form at design time.
OnVisibleChange was executed and in the handler I had logic that woul
only work at run-time, not at design time.
This is not behavior that I would expect. What is the purpose o
having .Net trigger control events at design time? How is thi
useful?
Joh
--
jdevine
jokiz - 23 Dec 2005 03:12 GMT
i believe it is normal since we are supposed to be interacting with the
same control at both runtime and designtime. there are ways to work
around this, detecting if the context is at designtime or runtime, etc.