Extending a RichTextBox

  • Thread starter Thread starter eBob.com
  • Start date Start date
E

eBob.com

I have an app which uses a RichTextBox. But now I'd like to associate some
data with the RTB. I know I could use the Tag property, but I'd much rather
create a new class which inherits from RTB and add a few fields to it. My
first problem is what do I want to add to the project? A "Component" or a
"UserControl" or a "Class"? And then all of those choices make me select a
template and I have no idea which template to use.

When I tried to do what seemed most logical to me (I think I was adding a
UserControl) I get an error message "Base Class
'System.Windows.Forms.RichTextBox' specified for class 'RTBx' cannot be
different from the base class '...UserControl' or one of its other partial
types."

Also, no matter what I have tried I do not see my "thing" (i.e. Component,
UserControl, whatever) in the Toolbox and therefore cannot drag and drop it
onto my Form1 in the designer.

Can anyone please give me some guidance on this?

Thanks, Bob
 
I have an app which uses a RichTextBox. But now I'd like to associate some
data with the RTB. I know I could use the Tag property, but I'd much rather
create a new class which inherits from RTB and add a few fields to it. My
first problem is what do I want to add to the project? A "Component" or a
"UserControl" or a "Class"? And then all of those choices make me select a
template and I have no idea which template to use.

When I tried to do what seemed most logical to me (I think I was adding a
UserControl) I get an error message "Base Class
'System.Windows.Forms.RichTextBox' specified for class 'RTBx' cannot be
different from the base class '...UserControl' or one of its other partial
types."

Also, no matter what I have tried I do not see my "thing" (i.e. Component,
UserControl, whatever) in the Toolbox and therefore cannot drag and drop it
onto my Form1 in the designer.

Can anyone please give me some guidance on this?

Thanks, Bob

Choose a class that inherits from RichTextBox. A user control is a
class which inherits from UserControl, and has a companion designer
file. What you had was two partial class files that pointed to two
different base types.

You won't see the new RichTextBox in the toolbox until you build, and
then only when you are viewing a form that it can be dragged onto. It
should show at the top of the toolbox in 'ProjectName' Components.
 
I have an app which uses a RichTextBox.  But now I'd like to associate some
data with the RTB.  I know I could use the Tag property, but I'd much rather
create a new class which inherits from RTB and add a few fields to it.  My
first problem is what do I want to add to the project?  A "Component"  or a
"UserControl" or a "Class"?  And then all of those choices make me select a
template and I have no idea which template to use.

When I tried to do what seemed most logical to me (I think I was adding a
UserControl) I get an error message "Base Class
'System.Windows.Forms.RichTextBox' specified for class 'RTBx' cannot be
different from the base class '...UserControl' or one of its other partial
types."

Also, no matter what I have tried I do not see my "thing" (i.e. Component,
UserControl, whatever) in the Toolbox and therefore cannot drag and drop it
onto my Form1 in the designer.

Can anyone please give me some guidance on this?

I added a FindAndReplace method to the RichTextBox control by creating
a class library for custom controls, and added a Component class for
it. Since this component was going to inherit from the RIchTextBox
control, it needed to reference System.Windows.Forms. This class could
either override existing methods or add new ones, which is what I did.
I don't see why it couldn't also add new properties, which it sounds
like what you want to do. I then dragged the DLL to the toolbox into a
special group I created just for custom controls. Then I could use it
in any project I wanted to.
 
I have an app which uses a RichTextBox. But now I'd like to associate some
data with the RTB. I know I could use the Tag property, but I'd much
rather
create a new class which inherits from RTB and add a few fields to it. My
first problem is what do I want to add to the project? A "Component" or a
"UserControl" or a "Class"? And then all of those choices make me select a
template and I have no idea which template to use.

When I tried to do what seemed most logical to me (I think I was adding a
UserControl) I get an error message "Base Class
'System.Windows.Forms.RichTextBox' specified for class 'RTBx' cannot be
different from the base class '...UserControl' or one of its other partial
types."

Also, no matter what I have tried I do not see my "thing" (i.e. Component,
UserControl, whatever) in the Toolbox and therefore cannot drag and drop
it
onto my Form1 in the designer.

Can anyone please give me some guidance on this?

I added a FindAndReplace method to the RichTextBox control by creating
a class library for custom controls, and added a Component class for
it. Since this component was going to inherit from the RIchTextBox
control, it needed to reference System.Windows.Forms. This class could
either override existing methods or add new ones, which is what I did.
I don't see why it couldn't also add new properties, which it sounds
like what you want to do. I then dragged the DLL to the toolbox into a
special group I created just for custom controls. Then I could use it
in any project I wanted to.
 
Back
Top