Click here to Skip to main content
15,899,124 members
Home / Discussions / C#
   

C#

 
GeneralRe: C++ guy missing pointers Pin
BadKarma15-Mar-06 21:59
BadKarma15-Mar-06 21:59 
GeneralRe: C++ guy missing pointers Pin
V.15-Mar-06 22:14
professionalV.15-Mar-06 22:14 
GeneralRe: C++ guy missing pointers Pin
BadKarma15-Mar-06 23:27
BadKarma15-Mar-06 23:27 
AnswerRe: C++ guy missing pointers Pin
J4amieC15-Mar-06 22:26
J4amieC15-Mar-06 22:26 
GeneralRe: C++ guy missing pointers Pin
BadKarma15-Mar-06 23:13
BadKarma15-Mar-06 23:13 
GeneralRe: C++ guy missing pointers Pin
J4amieC15-Mar-06 23:42
J4amieC15-Mar-06 23:42 
AnswerRe: C++ guy missing pointers Pin
mcljava17-Mar-06 5:03
mcljava17-Mar-06 5:03 
QuestionWhy is my inherited window forms control deleted Pin
Tony_Joh15-Mar-06 21:15
Tony_Joh15-Mar-06 21:15 
Hello!

I have a very specific question and that is about how to inherit a visual
control for example the control System.Windows.Forms.TextBox without causing
the environment to delete the control when there are some compile errors.
It's the same problem with any visual control that you inherit. The control
is deleted as soon as you use the View Designer when there is compile error.


It's very easy to reproduce my problem. You can do it in this way.
1. Create a class called ExtTextBox like this. In my example here I have
removed the namespace. But if you include namespace make sure you have
access to it.
public class ExtTextBox : System.Windows.Forms.TextBox
{
public ExtTextBox() {}
}
As you can see this class ExtTextBox inherit from the ordinary components
System.Windows.Forms.TextBox in the .NET framework

2. Create a windows form with any name. The default is Form1

3. Use the View Designer and drag the control TextBox into the window form.
My control was called textBox1

4. Because I want the control textBox1 to be an instance of ExtTextBox I
have to edit the InitializeComponent() I don't have any other idea.
Here is an extract from my windows form called Form1.
Only the interesting rows is written. Two rows is important here.
First saying that control textBox1 is of type ExtTextBox.
Second edit the InitializeComponent and say that textBox1 is an instance of
ExtTextBox.
public class Form1 : Form
{
private ExtTextBox textBox1;

...
...
...

Private void InitializeComponent()
{
this.textBox1= new ExtTextBox();
...
...
...
}
}

5 Compile. Hopefully you don't get any compile errors. When you run the
application only the textBox is being displayed. The problem might start
even here. If you get any compile error and you use the View Designer the
control named textBox1 is being deleted.

6 If you don't get any compile error make a change so you get a compile
error and then use the View Designer the control named textBox1 is being
deleted.

7 Now to my question. I can't use controls that being deleted automatically
when I get compile error as soon as I use the View Designer.

8. If I want to use inheritance on visual control how do I do. I just can't
have it as it is now.

9 I just can't use inheritance in the way I do now.

10. I hope that you have a good suggestion how I should use inheritance on
visual control to avoid this kind of problems.


Additional information: I have a project containing
several forms and some code class files. One file in the project is a code
class file which contains this ExtTextBox in this way.
public class ExtTextBox : System.Windows.Forms.TextBox
{
public ExtTextBox() {}
}

When you build the project(assemby) and you get some compile error and you
then use the View Designer on a form containing this inherited control the
control will be deleted.

I have also noted that you can avoid that the control is being deleted but
it's a very annoying way to do it on.
Before you build the project(assembly) you click on Windows->Close All
documents.
Then you build and you get some compile error and you can still use the View
Designer and see the control.
I just can't use that solution having to close all the documents every time
before I build the project.

When I use inheritance I want to extend for example the TextBox class by
additional functionality.
If I create a userControl(see below) for example like this. I can't extent
the class TextBox with additional functionality because the control is a
member in the UserControl class. I can extend the functionality of class
UserControl1 but that is not what I want.
public class UserControl1 : System.Windows.Forms.UserControl
{
private System.Windows.Forms.TextBox textBox1;
...
...
...
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox():
...
...
...
}
}

So the main question is how do I do if I want to inherit(extend) a visual control class for example TextBox without having the TextBox control to be deleted as soon as I use View Designer.

Is it possible that my problem is a kind of bug in the .NET framework.
I use VS 2003.

//Tony


QuestionDataSet Problem Pin
Ali Zubairy15-Mar-06 18:58
Ali Zubairy15-Mar-06 18:58 
QuestionIP ADDRESS - Problem Pin
Jijo BP15-Mar-06 18:27
Jijo BP15-Mar-06 18:27 
AnswerRe: IP ADDRESS - Problem Pin
Guffa15-Mar-06 18:36
Guffa15-Mar-06 18:36 
GeneralRe: IP ADDRESS - Problem Pin
Jijo BP15-Mar-06 19:29
Jijo BP15-Mar-06 19:29 
QuestionHow to use IPersistStreamInit? Pin
zhaoyu16215-Mar-06 18:06
zhaoyu16215-Mar-06 18:06 
QuestionReg Nullable.Wrap function Pin
Kiran Kumar Singani15-Mar-06 17:39
Kiran Kumar Singani15-Mar-06 17:39 
QuestionCan not use RightClick/Past when i catch Keys in TextBox? Pin
superdragon15-Mar-06 17:23
superdragon15-Mar-06 17:23 
AnswerRe: Can not use RightClick/Past when i catch Keys in TextBox? Pin
superdragon15-Mar-06 19:21
superdragon15-Mar-06 19:21 
QuestionSearch function in Crystal Report Pin
angelagke15-Mar-06 15:33
angelagke15-Mar-06 15:33 
QuestionBar code component connect to computer? Pin
notIdea15-Mar-06 14:43
notIdea15-Mar-06 14:43 
AnswerRe: Bar code component connect to computer? Pin
mcljava15-Mar-06 18:21
mcljava15-Mar-06 18:21 
QuestionI’m a c++ guy and C#’s List scares me. Pin
Julien15-Mar-06 12:37
Julien15-Mar-06 12:37 
GeneralRe: I’m a c++ guy and C#’s List scares me. Pin
George L. Jackson15-Mar-06 17:54
George L. Jackson15-Mar-06 17:54 
GeneralRe: I’m a c++ guy and C#’s List scares me. Pin
Julien15-Mar-06 18:25
Julien15-Mar-06 18:25 
QuestionDatagrid help Pin
bazzanewt15-Mar-06 11:56
bazzanewt15-Mar-06 11:56 
AnswerRe: Datagrid help Pin
Robert Rohde15-Mar-06 18:28
Robert Rohde15-Mar-06 18:28 
QuestionCapture mouse with transparent forms Pin
AbyssNOLF15-Mar-06 9:37
AbyssNOLF15-Mar-06 9:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.