473,772 Members | 2,411 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

inherit TextBox control

Hi,
I have a dialog with 2 TextBox controls.
I want to add some functionality to one of the them.
I created a class MyTextBox which inherits from TextBox.
How can I connect one of the TextBox controls to my new class ?

Yoav.
Oct 7 '07 #1
3 4671
"Yoavo" <yo**@cimatron. co.ilwrote in message
news:ei******** ******@TK2MSFTN GP04.phx.gbl...
I have a dialog with 2 TextBox controls.
I want to add some functionality to one of the them.
I created a class MyTextBox which inherits from TextBox.
How can I connect one of the TextBox controls to my new class ?
You don't exactly "connect" the textbox with the new class. Instead, the
textbox has to be an instance of the new class. Search your source code for
the place where the textbox is declared and initialized. If you are using
Visual Studio 2002/2003, this is in the .cs file for your Form in the block
labelled "designer generated code". If You are using VS 2005, you have to
click on the icon "show all files" in solution explorer, and then open the
file with the extension .designer.cs. You will find declarations similar to
this ones:

TextBox texbox1;
...
textbox1 = new TextBox();

In those two lines, replace TexBox with MyTextBox, and you are done.

Another way to do it is to compile your new class into a dll, and then
add it to the toolbx in the windows forms designer (right-click on the
toolbox). Once you do that, the MyTextBox will appear in the toolbox, and
you can drag it from there into your form just like the standard textbox. If
you are using version 2005, you don't need to do any of this, since the
controls defined inside your project will appear automatically at the top of
the toolbox, under "myproject components".
Oct 7 '07 #2
I am using VS 2005 and my application is a WPF program.
The wizard created a file "Window1.g. cs" and in it there is the window
class:
public partial class Window1 : System.Windows. Window,
System.Windows. Markup.ICompone ntConnector {
....
internal System.Windows. Controls.TextBo x YoavTextBox;
}
with the method:
void System.Windows. Markup.ICompone ntConnector.Con nect(int connectionId,
object target) {
....
this.YoavTextBo x = ((System.Window s.Controls.Text Box)(target));
}

when I tried to replace "System.Windows .Controls.TextB ox" with "MyTextBox" ,
I got compilation errors.

"Alberto Poblacion" <ea************ *************** ***@poblacion.o rgwrote
in message news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
"Yoavo" <yo**@cimatron. co.ilwrote in message
news:ei******** ******@TK2MSFTN GP04.phx.gbl...
>I have a dialog with 2 TextBox controls.
I want to add some functionality to one of the them.
I created a class MyTextBox which inherits from TextBox.
How can I connect one of the TextBox controls to my new class ?

You don't exactly "connect" the textbox with the new class. Instead, the
textbox has to be an instance of the new class. Search your source code
for the place where the textbox is declared and initialized. If you are
using Visual Studio 2002/2003, this is in the .cs file for your Form in
the block labelled "designer generated code". If You are using VS 2005,
you have to click on the icon "show all files" in solution explorer, and
then open the file with the extension .designer.cs. You will find
declarations similar to this ones:

TextBox texbox1;
...
textbox1 = new TextBox();

In those two lines, replace TexBox with MyTextBox, and you are done.

Another way to do it is to compile your new class into a dll, and then
add it to the toolbx in the windows forms designer (right-click on the
toolbox). Once you do that, the MyTextBox will appear in the toolbox, and
you can drag it from there into your form just like the standard textbox.
If you are using version 2005, you don't need to do any of this, since the
controls defined inside your project will appear automatically at the top
of the toolbox, under "myproject components".


Oct 8 '07 #3
"Yoavo" <yo**@cimatron. co.ilwrote in message
news:uv******** ******@TK2MSFTN GP06.phx.gbl...
>I am using VS 2005 and my application is a WPF program.
Ah, sorry. Since you didn't specify, I thought you were doing a plain
old WinForms application. I have played a little bit with WPF, but I have
not gone far enough to know how to subclass controls on this platform.
Someone more knowledgeable than me will have to provide the answer.

Oct 8 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1578
by: Steve | last post by:
Visual Studio 2003 .Net / C# I have a 2 page Tab Control for users to add a Job in my application. The first page is for them to choose which type of Job they would like. The type of Job determines what information is asked for on the second page, and so will determine the layout of the second page. So this second page needs to be determined at runtime really when they select the Job Type on page 1. I thought I could maybe define...
0
2174
by: Jax | last post by:
I am using a class that inherits from the DataGridTextBoxColumn. It adds a combo box into the column where it displays a selection of choices. The problem I have is that when this comboBox loses focus I lose the selected text. And this next line isn't setting the text in the cell. // code within the custom DataGridComboBoxColumn class this.TextBox.Text = this.ComboBox.SelectedItem.ToString();
6
2911
by: Mohammad-Reza | last post by:
I wrote a component using class library wizard. In my component i want to in order to RightToLeft property do some works. I can find out if user set this property to Yes or No, But if He/She set it to Inherit I must examine its parent RightToLeft property(if i`m wrong please tell me) but in this component that inherits from System.ComponentModel.Component, How can i find parent??? In UserControls we can simply use Parent property but in...
5
7143
by: Mike L | last post by:
This is my first attempt at inheriting a class. I want to inherit textbox class to my derived class ClassNum. ClassNum will override the TextChanged, Leave, KeyPress and Enter methods. So, far I was able to inherit the textbox class to ClassNum, but I get errors when I try to override the methods. class ClassNum : System.Windows.Forms.TextBox {
8
1701
by: Issac | last post by:
Hi, I created an Inherit UserControl which inherits textbox with additional property say 'Type'. I used in my forms and everything works fine. But afterward, I want to remove (or rename) such property. I find that the auto inserted code (InitializeComponent) for that UserControl's property doesn't get update, and I got tons of errors from wherever I referenced it. Do I need to manually update InitializeComponent module in every...
11
1306
by: Frank | last post by:
Hello, plse help me on the way. I know how class textboxuser inherits from textbox works. But how is this done: a button and a textbox, if I push the button the textbox is filled with 'great'. These two controls I want to pack into something and use it as a whole in other forms. Is this done with a container, component? Plse supply a small example. Thanks a lot Frank
1
1420
by: mtczx232 | last post by:
I going to drive my own Inherit control for All Win control, But I see that inherit control not get by default the original control Icon. How i can get the original Icon for each Inherit control?
3
1944
by: justsome_newbie | last post by:
Sorry for posting another question, but I can't seem to get the hang of ASP.Net. In windows apps if I want to extend a control I would just create a class that inherits from that control and do add/overload/override the necessary properties and methods. This apparently doesn't work in Asp.Net, or at least I can't get it to. Take the simple class below: public class MyTextBox : System.Web.UI.WebControls.TextBox {
2
2269
by: Joe | last post by:
Is it possible to inherit from a UserControl? If I try my user control class is not recognized. Thanks, Joe
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9914
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8937
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7461
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6716
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5355
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4009
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3610
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.