473,396 Members | 2,113 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,396 software developers and data experts.

controls and custom property

I am dynamically creating labels. I would like to be
able to attach custom properties(?) to the labels so that
I can query the property for the data in it later. Is
this possible, and how do I start?

thnx
Ev
Nov 20 '05 #1
10 1352
Cor
Hi Everet
Here an example I did made once with buttons I thought I did it because I
did need a propertie that was not on a label.
I am dynamically creating labels. I would like to be
able to attach custom properties(?) to the labels so that
I can query the property for the data in it later. Is
this possible, and how do I start?

\\\
Private mybutton(31) As Button
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim start As Integer = 4
Dim top As Integer = 25
Dim i As Integer
For i = 0 To System.DateTime.DaysInMonth(2003, 10) - 1
mybutton(i) = New Button
mybutton(i).TextAlign = ContentAlignment.MiddleCenter
mybutton(i).Width = 40
mybutton(i).Height = 20
mybutton(i).FlatStyle = FlatStyle.Flat
mybutton(i).BackColor = Drawing.Color.AntiqueWhite
mybutton(i).Location = New System.Drawing.Point(start, top)
mybutton(i).Text = (i + 1).ToString
mybutton(i).Cursor = Cursors.Hand
Me.Controls.Add(mybutton(i))
AddHandler mybutton(i).Click, AddressOf mybutton_Click
start = start + 40
If (i + 1) Mod 5 = 0 Then
top = top + 20
start = 4
End If
Next
End Sub
Private Sub mybutton_Click _
(ByVal sender As Object, ByVal e As System.EventArgs)
Dim month As Button = DirectCast(sender, Button)
MessageBox.Show("The day is: " & month.Text)
End Sub
End Class
///

I hope this is it a little bit?

Cor
Nov 20 '05 #2
Everett,
You could use the Tag property of the Label (major ick! ;-))

Or you create a custom Label class, by inheriting from Label with the custom
properties that you need.

Public Class EverettLabel
Inherits Label

Private m_prop1 As Integer
Private m_prop2 As Integer
Private m_prop3 As String

Public Sub New(text As String, prop1 As Integer, _
prop2 As Integer, prop3 As Integer)
me.Text = text
m_prop1 = prop1
m_prop2 = prop2
m_prop3 = prop3
End Class

Public Property Prop1 As Integer
Public Property Prop2 As Integer
Public Property Prop3 As String

End Class

Then when you create the label you create a EverettLabel instead and set the
properties. If you noticed I added a constructor to simplify create
EverettLabel labels.

I prefer the custom label approach as you can give it type safe properties,
and optionally embed the behavior in the class itself (so you do not need to
handle its events in multiple forms).

Hope this helps
Jay
"everett" <ev*****@creativedigitalgroup.com> wrote in message
news:06****************************@phx.gbl...
I am dynamically creating labels. I would like to be
able to attach custom properties(?) to the labels so that
I can query the property for the data in it later. Is
this possible, and how do I start?

thnx
Ev

Nov 20 '05 #3
in addition (tag is an object wats icky about that??)

you can also create your own tag class (normall class that you can place in
the tag property of everything) you can put as many properties in there that
you need
label(2).tag.prop1

"everett" <ev*****@creativedigitalgroup.com> wrote in message
news:06****************************@phx.gbl...
I am dynamically creating labels. I would like to be
able to attach custom properties(?) to the labels so that
I can query the property for the data in it later. Is
this possible, and how do I start?

thnx
Ev

Nov 20 '05 #4
Eric,
As I stated at the bottom of my post: "I prefer the custom label approach
as you can give it type safe properties, and optionally embed the behavior
in the class itself (so you do not need to
handle its events in multiple forms)."

Tag is not type safe, it is a property of type Object, you can stash
anything you want in there, other developers could in inadvertently change
what is stored in there causing hard to find runtime errors.

Also because Tag is of type Object, you have to cast it to the object type
when using Option Strict On, you are using Option Strict on aren't you?
Option Strict On helps avoid hard to find runtime errors.

Your example:
label(2).tag.prop1
With option strict on becomes:
DirectCast(label(2).Tag, MyTagClass).Prop1

Hope this helps
Jay

"EricJ" <ericRéMo**@ThiSomnipack.be> wrote in message
news:3f***********************@reader3.news.skynet .be... in addition (tag is an object wats icky about that??)

you can also create your own tag class (normall class that you can place in the tag property of everything) you can put as many properties in there that you need
label(2).tag.prop1

"everett" <ev*****@creativedigitalgroup.com> wrote in message
news:06****************************@phx.gbl...
I am dynamically creating labels. I would like to be
able to attach custom properties(?) to the labels so that
I can query the property for the data in it later. Is
this possible, and how do I start?

thnx
Ev


Nov 20 '05 #5
> Also because Tag is of type Object, you have to cast it to the object type
when using Option Strict On, you are using Option Strict on aren't you?
Option Strict On helps avoid hard to find runtime errors.


/me looking at the plant behind my shoulder, slightly blushing ;p

I agrea that it is better, but Option Strict wil have to wait till my next
project (i"m not going over +17k lines of code to change it)

eric
Nov 20 '05 #6
Cor
"EricJ"

Hi Eric, there was a time, that Armin did answer all questions, with

"Did you enable option Strict"

You understand it, big discussions between Armin on one side and Nick(Nak),
Fergus and Cor on the other side Herfried was somewhere in the middle. (This
was used to build the longest thread ever Fergus and Nick said).

Nick and Cor are using consequently "option strict on" now and I thought
Fergus when it is real.

I would use it if I was you every time I started a new class on a seperate
page.

It real helps and your code becomes faster (although sometimes you have to
write something more and to think a lot when it is a Com object).

Just an advice

Cor

Nov 20 '05 #7
i know its better (but lazy habbits die hard) and i din't give it much
thought before. i will try to implement it as i go along.
I'll give you a bit background info
I finished school this year and admitted i learned a lot there but theres to
mutch (in real world applications) that they never mentionned, I know this
and I still have a lot to learn. (i guess we'll all be learning new things
and methots for the rest of our lives)

I'm always open to remarks on my code and better ways to do things. I find
this newsgroup one of the best places to learn and get better, trying to
help others in the progress. :)

eric

ps cor are you from belgium, the netherlands? (i thought i remeberd you
saying once your dutch)

Nov 20 '05 #8
Cor
Original Amsterdam (Jordaan)

Which Belgium part are you from Dutch or French?
ps cor are you from belgium, the netherlands? (i thought i remeberd you
saying once your dutch)


Nov 20 '05 #9
the dutch part :)

"Cor" <no*@non.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
Original Amsterdam (Jordaan)

Which Belgium part are you from Dutch or French?
ps cor are you from belgium, the netherlands? (i thought i remeberd you
saying once your dutch)


Nov 20 '05 #10
Thanks for your help -
i ended up making a custom control using the add custom
control, inherting the label, and adding the properties I
needed.
---Original Message-----
in addition (tag is an object wats icky about that??)

you can also create your own tag class (normall class that you can place inthe tag property of everything) you can put as many properties in there thatyou need
label(2).tag.prop1

"everett" <ev*****@creativedigitalgroup.com> wrote in messagenews:06****************************@phx.gbl...
I am dynamically creating labels. I would like to be
able to attach custom properties(?) to the labels so that I can query the property for the data in it later. Is
this possible, and how do I start?

thnx
Ev

.

Nov 20 '05 #11

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

Similar topics

16
by: TD | last post by:
This is the code under a command button - Dim ctl As Control For Each ctl In Me.Controls If ctl.BackColor <> RGB(255, 255, 255) Then ctl.BackColor = RGB(255, 255, 255) End If Next ctl
1
by: Earl Teigrob | last post by:
Background: When I create a ASP.NET control (User or custom), it often requires security to be set for certain functionality with the control. For example, a news release user control that is...
0
by: Earl Teigrob | last post by:
I am building a custom control that I want to server as a container for child controls that can be dynamically added to this control. I can persist the child controls that are added to my custom...
9
by: james.e.coleman | last post by:
Hello, I have created a custom dropdownlist that is used multiple times within a single page. When trying to set the values of the controls with the page in which they are being used, they all...
0
by: Jeremy Chapman | last post by:
I have included below virtually all the code to a control I'm trying to build. My issue is that an array list property in my control does not get persisted properly to the aspx page code in design...
3
by: Adrian Parker | last post by:
v1.1 and v2.0 We have a problem with viewstate not being stored. What's happening is that we create controls in CreateChildControls and add them to a container on the page (whether it be a...
2
by: Laurent Bugnion | last post by:
Hi, I like to develop custom controls for a number of webpages. These controls are often customizable, so that they can be reused in a number of situations. My question is: What is the best...
6
by: | last post by:
I have made some user controls with custom properties. I can set those properties on instances of my user controls, and I have programmed my user control to do useful visual things in response to...
15
by: rizwanahmed24 | last post by:
Hello i have made a custom control. i have placed a panel on it. I want this panel to behave just like the normal panel. The problem i was having is that the panel on my custom control doesnt...
1
by: Don | last post by:
I'm getting the following exception displayed in the task list at design time for my project: "Code generation for property 'Controls' failed. Error was: 'Object reference not set to an...
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...
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
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,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...

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.