ControlDesigner for custom control

M

mohit

Hello,

I am making a custom control which places some restrictions on the
value of Text property of the control.
While debugging i noticed that when the control is drag-dropped on a
form during Design Time, the InitializeNewComponent method of the
ControlDesigner is invoked. After this the text property of my control
is set to the control name, which Visual Studio automatically assigns(
name of the control object like textBox1 ...).

Now if I want a default blank value in the control's text property i
can set my own designer, override the InitializeNewComponent method and
set the text value after i call the base InitializeNewComponent method

public override void InitializeNewComponent(IDictionary defaultValues)
{
base.InitializeNewComponent(defaultValues);
//over here text property is smthing like MyControl1 or
MyControl2
MyControl control1 =this.Component as MyControl ;
control1.Text = "";
}

My question is why is this happening ??

Even in Microsofts controls like TextBox when I drag the control on the
form during designtime the text property is set to the control's
instance name and then immediately(within milli seconds) cleared.

Thanks and Regards,
Mohit
 
C

chanmm

I did play with Customer User Control for textbox but when I drag to the
form it is blank in my textbox though.

chanmm
 
M

mohit

chanmm said:
I did play with Customer User Control for textbox but when I drag to the
form it is blank in my textbox though.

chanmm
Hello chanmm ,
If you override the Text property and debug it you will notice that the
text property is set to control name and then to string.Empty. The end
result is a blank value but before that the control name is set. You
may notice it in the designer as a brief flicker just when you drop the
control on the form.

Anyways thanks for responding.
If I do find some lead on this i will post it here.

thanks and regards,
mohit
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top