473,671 Members | 2,163 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding Method to TextBox

Hi .Net experts,

I am trying to build a user control of textbox and would like to add a
public method to the object like

public void CheckOptions(st ring str)
{
// codes here
}

So over the WinForm, I would expect the following to work

txtMane.CheckOp tions("Hello"); //txtMane is the reference to the user
control

But it does not. How can I make it happen?

Thanks

Casper
Nov 17 '05 #1
3 2065
On 30 Mar 2005 08:02:30 -0800, Casper wrote:
Hi .Net experts,

I am trying to build a user control of textbox and would like to add a
public method to the object like

public void CheckOptions(st ring str)
{
// codes here
}

So over the WinForm, I would expect the following to work

txtMane.CheckOp tions("Hello"); //txtMane is the reference to the user
control

But it does not. How can I make it happen?

Thanks

Casper


What does not work? Can't you compile it? Do you get a runtime error? Give
some more information.

--
Claudio Grazioli
http://www.grazioli.ch
Nov 17 '05 #2
You need to create a control that inherits from TextBox. You then add
your appropriate methods. Possibly overriding existing membeers
depending upon what you need to do. Then instead of using the TExtbox
you find your control in the toolbox after adding a reference to it.
Due to several major flaws in VS.NET's design it is best to create a
seperate Windows Control Library project in the same solution and add a
project reference and then add the dll to your toolbox. This for the
most part is being fixed in vs2k5 so that the controls automatically
show up in vs.net's toolbox.

Hope this helps

#region "Using Directives"
using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Drawing;
using System.Data;
using System.Windows. Forms;
#endregion

namespace WindowsApplicat ion2
{
#region "Summary - Description for CustomControl1"
/// <summary>
/// Summary description for CustomControl1.
/// </summary>
#endregion
[ToolboxItem(tru e)]
public class CustomControl1 : TextBox
{
#region "Variables - Form Designer Controls"
private System.Componen tModel.Containe r components = null;
#endregion
#region "Constructo rs"
public CustomControl1( )
{
InitializeCompo nent();
}
#endregion
#region "Destructor s"
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
components.Disp ose();
}
base.Dispose( disposing );
}
#endregion
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
components = new System.Componen tModel.Containe r();
}
#endregion
#region "Methods - Overridden"
protected override void OnPaint(PaintEv entArgs pe)
{
// TODO: Add custom paint code here

// Calling the base class OnPaint
base.OnPaint(pe );
}
#endregion
public void CheckOptions()
{
// Your code implementations goes here
}
}
}

Nov 17 '05 #3
Marc, Claudio, & Others:

I wonder if I could expand the question a bit. I have an idea for
automating the population of many of the controls on a form. My intention is
to place a unique keyword in the Tag property. Then one set of [inherited]
code will look for the presence of this keyword, and if present, will use it
to retrieve data from a centralized location.

To accomplish this, ideally I'd like to alter the default "Load" method of
the base Control object. That way, this method will be inherited by all of
the native controls.

Is there a simple way to accomplish this?

Robert Werner
MWTech


Nov 17 '05 #4

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

Similar topics

4
1937
by: slylos | last post by:
I've got a Windows form that has a TabControl. I add TabPages to this TabControl at Runtime, along with two Textboxes and a button. The problem I'm having is I can't figure out how to reference the Textboxes elsewhere once they have been created. The TextBoxes are being named based on a private global counter (i.e. TextBox tb = new TextBox(); tb.Name = "tb" + (counter++).ToString();) They are being created in a private method called...
3
4873
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that the best method? Do you have a sample of how to do this?
1
4720
by: Jack | last post by:
Hi, I have a page with a repeater control that contains textboxes. I'm trying to create a validation class that is called by my page. A method in this class iterates through all the controls on the page. On encountering a TextBox control, it looks at the ID to discern the field the TextBox represents, and then creates the appropriate validation controls and adds them to the page. The controlToValidate property of each validation...
0
1407
by: Luis Esteban Valencia | last post by:
Please help me if possible Its only adding a row. When I click again it steps into the function but doesnt add it to the page. Private Sub LinkButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LinkButton2.Click Dim tcells As TableCellCollection
2
1188
by: Husam | last post by:
Hi EveryBody: How can I add Sub or Function or property to be a member of TextBox ? For example TextBox1.Text , text is a property in Textbox1 How Can I add the following sub to be a member of textbox1: Public Sub SaveHtml(ByVal stream As Stream) If stream Is Nothing Then Throw New ArgumentNullException("SaveHtml : Must specify a
1
5047
by: Pranil Kanderi | last post by:
I have a huge application with lots of custom controls. The app had a memory leak but fixed that by calling the dispose method where needed and now the user objects are very stable, when I am looking at the task manager. But the GDI handles keep growing. I narrowed it down to having System.Drawing.Font in my custom controls. To test it out: I created a simple form with two buttons Add and Remove that - adds and removes a simple textbox....
4
1663
by: Duncan Dimech | last post by:
Dear All I am writing a tool which requires to have controls added to it dynamically. To make the task more complex, the addition of the control cannot happen anywhere but it has to be instead of a token example <pthis is a test <textbox /and a text box should be entered </P> the tool should render the message and instead of <textbox /it should
0
1842
by: EricLondaits | last post by:
Hi, I have an ASP.NET page with a ListBox that is data bound to a table with a single field (it holds a list of valid IDs). The page also has a textBox into which you can add new valid IDs, one per line (this is in order to make the process of adding new IDs easy, since it's only done at time of configuration). I have no problem with retrieving the contents of the textBox, splitting it into a string array, validating the individual...
2
7657
by: Ken Fine | last post by:
I want to add the security question and answer security feature to the ChangePassword control. I am aware that this functionality is built into the PasswordRecovery tool. I have implemented the PasswordRecovery with a Password reset required; a temporary password is sent to the account on file. I want an extra layer of security to accommodate the very unlikely contingency that someone's e-mail account is compromised. Challenging with the...
0
8912
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8819
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7428
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...
0
5692
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
4222
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
4403
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2809
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
2049
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1807
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.