473,394 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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(string str)
{
// codes here
}

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

txtMane.CheckOptions("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 2047
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(string str)
{
// codes here
}

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

txtMane.CheckOptions("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.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
#endregion

namespace WindowsApplication2
{
#region "Summary - Description for CustomControl1"
/// <summary>
/// Summary description for CustomControl1.
/// </summary>
#endregion
[ToolboxItem(true)]
public class CustomControl1 : TextBox
{
#region "Variables - Form Designer Controls"
private System.ComponentModel.Container components = null;
#endregion
#region "Constructors"
public CustomControl1()
{
InitializeComponent();
}
#endregion
#region "Destructors"
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
components.Dispose();
}
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 InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
#region "Methods - Overridden"
protected override void OnPaint(PaintEventArgs 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
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...
3
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...
1
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...
0
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,...
2
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...
1
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...
4
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...
0
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...
2
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...
0
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...

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.