Re: Addnew() by BonnieBerentCMVP
BonnieBerentCMVP
Fri Feb 18 17:37:03 CST 2005
Let me give you a little Jump Start on sub-classes. Sub-classing the base
controls is the first thing one should do in any language. I've been doing it
for years ... way before I ever started with .NET. There are always little
quirks in behavior in some of the base class controls that you want to get
around for every instance of an object.
Say, as an example, that you've developed a few forms for your application.
You've used the base class controls. At some point, you find something's not
quite acting right and you want to change that behavior or you may just want
to add something (some properties or something) to every ComboBox that you
use. Now, since you used the base class controls to begin with ... guess
what? You're outta luck!! You've got a lot of work ahead of you to change all
those. Whereas, if you had sub-classed all the controls first (even if you
haven't as yet put code in those sub-classes) and used the sub-classed
controls on your forms, then you'll have no extra work to do when you make
changes to your sub-classed control. (and yes, even the form should be
sub-classed).
Basically, you'll want a class library that contains your sub-classed UI
controls, like textbox, button, checkbox, 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.
And this is what I was talking about when I said to put a Format
eventhandler in your CheckBox ... put it in the sub-class and then you'll
never have to worry about it again.
I hope this helps you get started!!
~~Bonnie
"Hemang Shah" wrote:
> Thanks Bonnie
>
> I don't mind taking the time to write subclass for null for datetimepicker,
> I just don't know how. Codeproject has a good control but according to the
> messages on it, its not fully operational. I can't even find a commercial
> control that I can pay for.
>
> I'll google subclass to see how do I do that.
>
> I know about the format & parse method. But don't I have to do that for
> each checkbox on my form ?
>
> I guess not, if there is a way to format the base checkbox control from
> where everyone is instanced from. I have to do this in a separate dll ? or
> I can do it in my app itself.
>
> I'm migrating from Access development as I wanted to take the plunge into
> "real" development, these are rough waters though.
>
> If you can point me to any article on this it would be great.
>
> Thanks a lot again
>
> HS
>