开发者

Vb.net Nickname an object?

Is it possible to do something like this:

Dim ThisThing as ThisThingToolStripMenuItem.Text

So i can later in the code just do ThisThing = "whatever开发者_运维技巧" ?


No, that won't work, but you can assign ThisThingToolStripMenuItem to a variable with a smaller name, but you still have to reference it as ThisThing.Text.

You can also use a delegate defined with a lambda expression:

Action<string> setter = (string s) => ThisThingToolStripMenuItem.Text = s;

...

setter("whatever");

In VB.Net:

Dim Setter = Sub(s) ThisThingToolStripMenuItem.Text = s

...

Setter("whatever")


A variable has to be a type so the best you can do is something like this...

Dim objYourShorterName As New ToolStripMenuItem

'Where 1 is the particular index of the ToolStripMenuItem you wish
'the variable to reference.
objYourShorterName = ToolStrip1.Items(1)

'You still have to use the Text property.
objYourShorterName.Text = "Blah"

You can write a Sub Procedure to do it for you too.

Private Sub ShorterName(ByVal strText As String)

   ToolStrip1.Items(1).Text = strText

End Sub

Then to change the text...

ShorterName("New Text")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜