473,385 Members | 1,379 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,385 software developers and data experts.

Picking the right control

Hello,

I have a set of textboxes and labels, created by

Dim txtSign as TextBox
dim lblSign as Label

Do
txtSign = New Textbox
lblSign = New Label
Loop until ...

AddHandler txtSign.TextChanged, AddressOf Sign_TextboxChanged

In the Private Sub Sign_TextboxChanged, I want to determine in which
TextBox the Change took place, so it can affect the corresponding Label.

Any idea on how to achieve this?

Many thanks and greetings,

Michel
May 13 '07 #1
1 822
Michel,

If you don't want to go down the route of deriving a class with a new
property, you can use the "Tag" property of the textbox to associate it with
a label. The example below isn't exactly as you require because I'm not
dynamically creating the control, but you may see the concept. In "New" I
add a reference to each label into the tag property of the box. When the
box text changes, I retrieve the label by casting the tag property of the
text box. This example requires two text boxes and two labels on a form
(Label1, Label2, TextBox1, TextBox2).
Robin


Public Class Form1

Public Sub New()

' This call is required by the Windows Form Designer.

InitializeComponent()

' Add any initialization after the InitializeComponent() call.

Me.TextBox1.Tag = Me.Label1

Me.TextBox2.Tag = Me.Label2

End Sub

Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBox1.TextChanged

Dim theLabel As Label = CType(TextBox1.Tag, Label)

theLabel.Text = TextBox1.Text

End Sub

Private Sub TextBox2_TextChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBox2.TextChanged

Dim theLabel As Label = CType(TextBox2.Tag, Label)

theLabel.Text = TextBox2.Text

End Sub

End Class

"Michel Vanderbeke" <mi***************@skynet.bewrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Hello,

I have a set of textboxes and labels, created by

Dim txtSign as TextBox
dim lblSign as Label

Do
txtSign = New Textbox
lblSign = New Label
Loop until ...

AddHandler txtSign.TextChanged, AddressOf Sign_TextboxChanged

In the Private Sub Sign_TextboxChanged, I want to determine in which
TextBox the Change took place, so it can affect the corresponding Label.

Any idea on how to achieve this?

Many thanks and greetings,

Michel


May 13 '07 #2

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

Similar topics

1
by: Dave Theese | last post by:
Hello all, I've been studying up on declarations (to write a parser for them) and came up with a complicated and contrived example. I just want to run it by the group to see if I've got it...
1
by: Adam Clauss | last post by:
I have a few variables that I want declared as global. To accomplish this, I made the files globals.h and globals.cpp. In globals.h I have the declarations for the structs, and one variable...
3
by: Scott Collens | last post by:
Hi there, does anyone know if it is possible to set a value in a user control and pick it up in the code behind. I'm trying to reuse the same user control and code behind for multiple pages but...
0
by: Gozirra | last post by:
I have a Windows forms application. It utilizes a web service in order to retrieve information. The web service runs in a server farm which is load balanced by a router based on session token. ...
8
by: Candace | last post by:
I am using the following code to pick off each digit of a number, from right to left. The number I am working with is 84357. So for the first iteration it should return the number 7 and for the...
0
by: =?Utf-8?B?RG9tIFNpbmNsYWly?= | last post by:
I wonder if anyone can advise me of the best way to pick up a 404 error in a web browser control on a windows form. By way of some background the control is being used to display nethelp for the...
2
Ali Rizwan
by: Ali Rizwan | last post by:
Hello all, I have a main folder name IMAGES and have sub folders of that name A,B,C,.....,Z. And the sub folders contain images with name like in Folder A : Apple, Anchor etc and in B : Ball, Bear,...
9
by: newbiegalore | last post by:
Hello everyone :-) , Thanks to the gentle people on this group for helping me out with previous issues. :-D This time round I am facing what I perceive as a simple problem, which I have not found...
0
by: Miles | last post by:
Mitrokhin wrote: Mac OS X 10.5 comes with a Python "xattr" package pre-installed, which the xattr command-line utility is built on top of. Furthermore, the resource fork can be accessed as an...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...

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.