控件和自定义属性 [英] controls and custom property

查看:89
本文介绍了控件和自定义属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在动态创建标签。我想

能够将自定义属性(?)附加到标签上,以便

我可以在稍后查询属性中的数据。这可能是

,我该如何开始?


thnx

Ev

解决方案

你好Everet

这里有一个例子,我用按钮做了一次,我以为我做了它因为我/ b $ b确实需要一个属性,不在标签上。

我正在动态创建标签。我希望能够将自定义属性(?)附加到标签上,以便我可以稍后查询属性中的数据。
这是可能的,我该如何开始?



\\\

私人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)=新按钮

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

如果(i + 1)Mod 5 = 0那么

top = top + 20

start = 4

结束如果

下一页

End Sub

Private Sub mybutton_Click _

(ByVal sender As Object,ByVal e As System.EventArgs )

Dim month As Button = DirectCast(发件人,按钮)

MessageBox.Show(" The day is:" &安培; month.Text)

结束子

结束班

///


我希望这个是一点点吗?


Cor


Everett,

您可以使用Tag属性标签(主要ick!;-))


或者您创建一个自定义Label类,通过继承Label并使用您需要的自定义

属性。


公共类EverettLabel

继承标签


私有m_prop1作为整数

私有m_prop2为整数

私有m_prop3为字符串


Public Sub New(text as String,prop1 As Integer,_

prop2作为整数,prop3 As Integer)

me.Text = text

m_prop1 = prop1

m_prop2 = prop2

m_prop3 = prop3

结束班级


公共财产Prop1作为整数

公共财产Prop2作为整数

公共财产Prop3 As String


结束班


然后,当您创建标签时,您将创建一个EverettLabel并设置

属性。如果你注意到我添加了一个构造函数来简化创建

EverettLabel标签。


我更喜欢自定义标签方法,因为你可以给它类型安全的属性,

并可选择在行中嵌入行为(因此您不需要

以多种形式处理其事件)。


希望这有帮助

Jay

" everett" < EV ***** @ creativedigitalgroup.com>在消息中写道

news:06 **************************** @ phx.gbl ... < blockquote class =post_quotes>我正在动态创建标签。我希望能够将自定义属性(?)附加到标签上,以便我可以稍后查询属性中的数据。这是可能的吗?我该如何开始?

thnx
Ev



此外(标签是一个对象wick icky关于那?? ??


你也可以创建自己的标签类(normall类,你可以放在

标签属性一切都可以。你可以在那里放多少属性

你需要

label(2).tag.prop1


"埃弗里特" < EV ***** @ creativedigitalgroup.com>在消息中写道

news:06 **************************** @ phx.gbl ... < blockquote class =post_quotes>我正在动态创建标签。我希望能够将自定义属性(?)附加到标签上,以便我可以稍后查询属性中的数据。这是可能的吗?我该如何开始?

thnx
Ev



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

解决方案

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


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



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



这篇关于控件和自定义属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆