Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
C#.Net Newbie Question - Subclassing A Button
Message
From
03/10/2005 14:01:21
 
 
To
03/10/2005 13:37:24
General information
Forum:
ASP.NET
Category:
Class design
Miscellaneous
Thread ID:
01017131
Message ID:
01055570
Views:
13
Yes, it does. Thank you, Bonnie. I was going to experiment with overriding/shadowing the property, but thought I was going in a wrong direction. Now I see the direction is right. What is wrong is probably .Net forms designer that uses classes from toolbox as a kind of template rather than tru classes in OOP terms. So sad...

Yuriy


>Yuri,
>
>Does this help? Message #939577
>
>~~Bonnie
>
>
>
>
>>Hi Bonnie,
>>
>>How would you set, for example, font at a subclass level so that it is inherited by instances of the controls when I place them on a form. If I set font property for a subclass, compile it into a library, add the library to Toolbox, drag the class from Toolbox to a form, the piece of code that sets Font property for the subclass gets copied into form's code. If at a later time I deside to change font for the subclass, it will have no effect on instances of the subclass I already placed on forms. Am I missing something?
>>
>>Thanks,
>>
>>Yuriy
>>
>>
>>>Kevin,
>>>
>>>You can't do it visually, but you can still put these kinds of sub-classes in your ToolBox in order to drag them onto your form.
>>>
>>>Basically, you'll want a class library that contains your sub-classed UI controls, like textbox, button, etc. Something like this:
>>>
>>>using System;
>>>using System.Drawing;
>>>using System.Collections;
>>>using System.ComponentModel;
>>>using System.Windows.Forms;
>>>using System.Data;
>>>
>>>namespace MyCompany.WinUI.MyClasses
>>>{
>>>	public class MyComboBox : System.Windows.Forms.ComboBox
>>>	{
>>>		// code here
>>>	}
>>>
>>>	public class MyTextBox : System.Windows.Forms.TextBox
>>>	{
>>>		// code here
>>>	}
>>>
>>>	public class MyButton : System.Windows.Forms.Button
>>>	{
>>>		// code here
>>>	}
>>>}
>>>
>>>That's it. These controls can't be sub-classed visually, but as you can see, it's easy enough to do it in code. I have all the basic controls sub-classed in one class library file. Once they're added to the ToolBox, then can be dragged onto any design surface in the IDE.
>>>
>>>To add to the ToolBox, do the following: When you have the IDE open in the designer view (not the code view), go to the ToolBox, right-click anywhere and choose the Add/Remove Items, click on Browse and find the .DLL where your sub-classed controls are (you obviously needed to have compiled the class library after you created it). That's it ... they'll then be added to your ToolBox.
>>>
>>>~~Bonnie
>>>
>>>
>>>
>>>>How do I subclass a command button in C#.Net?
>>>>
>>>>I'd like to do it visually, so I can then drag my class onto
>>>>a form.
>>>>
>>>>Thanks
Yuri Rudenko
MCSD, MCP
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform