By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,473 Members | 3,598 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,473 IT Pros & Developers. It's quick & easy.

(HW) Adding custom controls within a project

P: n/a
Hi,

I have created a custom textBox within a C# project. I want to put that
custom textBox on a form now. I heard about a way, to place that user
control onto a form within the same project, without having to compile it
seperately before.

An example:

1. In Visual Studio create a new C# Windows Application
2. Add a User Control to the Project
3. Modify the code of the control so that it inherits from
System.Windows.Forms.TextBox
4. Overwrite some function (i. e. OnDragEnter)

protected override void OnDragEnter(DragEventArgs drgevent)
{
MessageBox.Show("Test");
base.OnDragEnter (drgevent);
}

5. ...and this is where I stuck: Add this modified textBox to the existing
Form1

It's not possible, to simply drag it on the Form (in Design View), like you
do with controls from the Toolbox. I know, that there's a way. I saw this a
couple of months before in some presentation, but cannot remember how the
guy did this.

Anybody out there knows?
Nov 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
The common way
Right Click the Toolbox and select "Add/Remove Items..."
Browse to your projects Bin directory and select the exe.
Click the OK button and the control will be added to the toolbox.
This will be on the toolbox of every project you now open.

The way I do it
Comment out the code for your control.
Change Inheritance from TextBox to UserControl.
Show the controls designer and rebuild the project.
The textbox control is now in your "My User Controls" tab.
Reset inheritance back to TextBox, uncomment the code and rebuild.
This will only be on the toolbox for your current project.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Helmut Wagensonner" <he****************@gmx.net> wrote in message
news:eQ**************@TK2MSFTNGP14.phx.gbl...
Hi,

I have created a custom textBox within a C# project. I want to put that
custom textBox on a form now. I heard about a way, to place that user
control onto a form within the same project, without having to compile it
seperately before.

An example:

1. In Visual Studio create a new C# Windows Application
2. Add a User Control to the Project
3. Modify the code of the control so that it inherits from
System.Windows.Forms.TextBox
4. Overwrite some function (i. e. OnDragEnter)

protected override void OnDragEnter(DragEventArgs drgevent)
{
MessageBox.Show("Test");
base.OnDragEnter (drgevent);
}

5. ...and this is where I stuck: Add this modified textBox to the existing
Form1

It's not possible, to simply drag it on the Form (in Design View), like
you do with controls from the Toolbox. I know, that there's a way. I saw
this a couple of months before in some presentation, but cannot remember
how the guy did this.

Anybody out there knows?

Nov 16 '05 #2

P: n/a
Thanks a lot! I will try immediately. I remember, that the guy in the
presentation used a different way - but anyway...

Thx, Helmut
"Mick Doherty"
<EX***********@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> schrieb
im Newsbeitrag news:eh*************@tk2msftngp13.phx.gbl...
The common way
Right Click the Toolbox and select "Add/Remove Items..."
Browse to your projects Bin directory and select the exe.
Click the OK button and the control will be added to the toolbox.
This will be on the toolbox of every project you now open.

The way I do it
Comment out the code for your control.
Change Inheritance from TextBox to UserControl.
Show the controls designer and rebuild the project.
The textbox control is now in your "My User Controls" tab.
Reset inheritance back to TextBox, uncomment the code and rebuild.
This will only be on the toolbox for your current project.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Helmut Wagensonner" <he****************@gmx.net> wrote in message
news:eQ**************@TK2MSFTNGP14.phx.gbl...
Hi,

I have created a custom textBox within a C# project. I want to put that
custom textBox on a form now. I heard about a way, to place that user
control onto a form within the same project, without having to compile
it seperately before.

An example:

1. In Visual Studio create a new C# Windows Application
2. Add a User Control to the Project
3. Modify the code of the control so that it inherits from
System.Windows.Forms.TextBox
4. Overwrite some function (i. e. OnDragEnter)

protected override void OnDragEnter(DragEventArgs drgevent)
{
MessageBox.Show("Test");
base.OnDragEnter (drgevent);
}

5. ...and this is where I stuck: Add this modified textBox to the
existing Form1

It's not possible, to simply drag it on the Form (in Design View), like
you do with controls from the Toolbox. I know, that there's a way. I saw
this a couple of months before in some presentation, but cannot remember
how the guy did this.

Anybody out there knows?


Nov 16 '05 #3

P: n/a
There is a My UserControls group in the toolbox that will show
UserControl-derived classes that were added in VS.NET to a referenced
project. They do sometimes appear in other circumstances, but I never
figured out why.

So, add Project1, add Project2, Reference Project1 in Project2, add a
UserControl to Project1, switch to Project2, and it should appear in the
MyUserControls group.

"Helmut Wagensonner" <he****************@gmx.net> wrote in message
news:eQ**************@TK2MSFTNGP14.phx.gbl...
Hi,

I have created a custom textBox within a C# project. I want to put that
custom textBox on a form now. I heard about a way, to place that user
control onto a form within the same project, without having to compile it
seperately before.

An example:

1. In Visual Studio create a new C# Windows Application
2. Add a User Control to the Project
3. Modify the code of the control so that it inherits from
System.Windows.Forms.TextBox
4. Overwrite some function (i. e. OnDragEnter)

protected override void OnDragEnter(DragEventArgs drgevent)
{
MessageBox.Show("Test");
base.OnDragEnter (drgevent);
}

5. ...and this is where I stuck: Add this modified textBox to the existing
Form1

It's not possible, to simply drag it on the Form (in Design View), like
you do with controls from the Toolbox. I know, that there's a way. I saw
this a couple of months before in some presentation, but cannot remember
how the guy did this.

Anybody out there knows?

Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.