Windows Develop Bookmark and Share   
 index > Windows Forms Designer > I can't seem to control the AutoSize's initial value of a label-derived control
 

I can't seem to control the AutoSize's initial value of a label-derived control

Hello.

I have this custom label that derives from System.Windows.Forms.Label. It is an automatic-growing label but height-wise, not width-wise. I'm sure most of you have seen some code for this lying around.

Anyway, the label functionality is working OK. I am now polishing it with a custom designer, but before I move on to the problems I am having with the designer, I must first need to solve an annoying problem: The AutoSize property value is being set to True in new instances of my label. I know that the standard Label control does this (changes AutoSize to true when dropped on a form), but I don't want this for my own label. Instead, I have defined that the default value AutoSize be False, while the default value for AutoSizeHeight be true.

If I debug an instance of Visual Studio 2008, I see where the AutoSize setter is called with True, which in turn forces AutoSizeHeight to False; the problem is that there is nothing more in the call stack except for external code. I just want this to stop. Any pointers as to how I can stop this?
MCP
webJose  Friday, September 04, 2009 2:13 PM
Ok, I found the solution. System.Windows.Forms.Label has a ToolboxItemAttribute attribute applied that identifies System.Windows.Forms.Design.AutoSizeToolboxItem as the toolbox item class to use, and the attribute is inheritable. Therefore, my label was also being created using the same type of toolbox item, which was forcing AutoSize to True when the control was created.

The solution? I applied the following to my version of the Label class:

[ToolboxItem(true)]

And that was it. :D
MCP
  • Marked As Answer bywebJose Friday, September 04, 2009 8:10 PM
  •  
webJose  Friday, September 04, 2009 8:10 PM
Ok, I found the solution. System.Windows.Forms.Label has a ToolboxItemAttribute attribute applied that identifies System.Windows.Forms.Design.AutoSizeToolboxItem as the toolbox item class to use, and the attribute is inheritable. Therefore, my label was also being created using the same type of toolbox item, which was forcing AutoSize to True when the control was created.

The solution? I applied the following to my version of the Label class:

[ToolboxItem(true)]

And that was it. :D
MCP
  • Marked As Answer bywebJose Friday, September 04, 2009 8:10 PM
  •  
webJose  Friday, September 04, 2009 8:10 PM

You can use google to search for other answers

Custom Search

More Threads

• ToolBox Tab
• Error in Updating database table using OdbcDataAdapter.Update() method
• How to Import a VS 2005 form into VS 2008
• CSS Stylesheet Editor Dialog in .NET application
• Image in treeview
• Anyone have components to sell?
• Property Browser
• Custom Designer Window
• Receiving Form Designer Error: "Type 'mpx.Controller' does not have a constructor with parameters of types DesignerHost."
• Lost my main form in designer