Creating a User Control

  • Thread starter Thread starter Dom
  • Start date Start date
D

Dom

Everytime I create a user control, (such as extending another control,
like TextBox), the IDE sticks into the Designer file, the following:

this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

In momst cases, this fails. Why is it there? I'm in the habit of
just commenting it out.

Dom
 
What do you mean "this fails"?  Are you saying that the Designer is  
actually inserting code that either fails to compile, or fails to execute  
(i.e. throws an exception)?

I've also seen this. The project fails to build with an error that
says the AutoScaleMode property is not a member of the object.
 
za got it exactly right. When you build, the error message says that
"AutoScaleMode property is not a member of the object", but the
Designer placed it in there.

Here are the steps I take if I want to extend a TextBox control:

1. I add a UserControl (i checked the designer.cs file, and you can
already see the offending line)
2. In the code window, I change "class MyTextBox : UserControl" to
"class MyTextBox : TextBox"
3. I build a constructor: "public MyTextBox () : base () {...}

As I said, right after step 1, I get the line about AutoScaleMode.

What am I doing wrong?
 
Thanks. That took care of everything. I'd like to get my hands on
the guy who came up with the name "UserControl".

Dom
 

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

Back
Top