Regarding $this

  • Thread starter Thread starter jason ji
  • Start date Start date
J

jason ji

Hi, buddies

I met expression like"$this" to reference a current
mainform control in VB.NET Winforms programming. I don't
know what $this stand for and how to use $. please advise.

thanks,

jason
 
* "jason ji said:
I met expression like"$this" to reference a current
mainform control in VB.NET Winforms programming. I don't
know what $this stand for and how to use $. please advise.

I never saw '$this' in VB.NET. Where did you see it?
 
Herfried K. Wagner said:
I never saw '$this' in VB.NET. Where did you see it?

I also only saw it in the (usually hidden) form*.resx files, but nowhere
else.
 
* "Brian Henry said:
I thought this was a c# / c++ thing

'this' is a C#/... thing. I now remember that I saw '$this' in the name
of ressources.
 
I have seen it.

For example where the form initializes it icon in the win form generated
code it uses $this

Check it out.

Shane
 
Hi,

The following is the source code I have seen in WinForm control example.


'
'frmMain
'
Me.AccessibleDescription =
CType(resources.GetObject("$this.AccessibleDescription"), String)
Me.AccessibleName =
CType(resources.GetObject("$this.AccessibleName"), String)
Me.Anchor = CType(resources.GetObject("$this.Anchor"),
System.Windows.Forms.AnchorStyles)
Me.AutoScaleBaseSize =
CType(resources.GetObject("$this.AutoScaleBaseSize"),
System.Drawing.Size)
Me.AutoScroll = CType(resources.GetObject("$this.AutoScroll"),
Boolean)
Me.AutoScrollMargin =
CType(resources.GetObject("$this.AutoScrollMargin"),
System.Drawing.Size)
Me.AutoScrollMinSize =
CType(resources.GetObject("$this.AutoScrollMinSize"),
System.Drawing.Size)
Me.BackgroundImage =
CType(resources.GetObject("$this.BackgroundImage"),
System.Drawing.Image)
Me.ClientSize = CType(resources.GetObject("$this.ClientSize"),
System.Drawing.Size)
Me.Controls.AddRange(New System.Windows.Forms.Control()
{Me.txtInvalidControls, Me.Button1, Me.rexPhone, Me.Label5, Me.Label4,
Me.Label3, Me.Label2, Me.Label1, Me.rexSsn, Me.rexIpAddress,
Me.rexEmail, Me.rexUsZipcode})
Me.Dock = CType(resources.GetObject("$this.Dock"),
System.Windows.Forms.DockStyle)
Me.Enabled = CType(resources.GetObject("$this.Enabled"),
Boolean)
Me.Font = CType(resources.GetObject("$this.Font"),
System.Drawing.Font)
Me.Icon = CType(resources.GetObject("$this.Icon"),
System.Drawing.Icon)
Me.ImeMode = CType(resources.GetObject("$this.ImeMode"),
System.Windows.Forms.ImeMode)
Me.Location = CType(resources.GetObject("$this.Location"),
System.Drawing.Point)
Me.MaximizeBox = False
Me.MaximumSize = CType(resources.GetObject("$this.MaximumSize"),
System.Drawing.Size)
Me.Menu = Me.mnuMain
Me.MinimumSize = CType(resources.GetObject("$this.MinimumSize"),
System.Drawing.Size)
Me.Name = "frmMain"
Me.RightToLeft = CType(resources.GetObject("$this.RightToLeft"),
System.Windows.Forms.RightToLeft)
Me.StartPosition =
CType(resources.GetObject("$this.StartPosition"),
System.Windows.Forms.FormStartPosition)
Me.Text = resources.GetString("$this.Text")
Me.Visible = CType(resources.GetObject("$this.Visible"),
Boolean)
Me.ResumeLayout(False)

I don't What '$this' means

thanks in advance.

jason
 
SStory said:
I have seen it.

For example where the form initializes it icon in the win form
generated code it uses $this

Check it out.

Right. That's what I thought I've tried to say.
 
jason ji said:
Hi,

The following is the source code I have seen in WinForm control
example.

Code:
I don't What '$this' means[/QUOTE]


$this is the language independent identifier for the Form.
 
Jason,
As Armin stated, its a (computer) language independent identifier for the
form used to change the (spoken/written) language displayed on the form.
'
'frmMain
'
Me.AccessibleDescription =
CType(resources.GetObject("$this.AccessibleDescription"), String)
Me.AccessibleName =
CType(resources.GetObject("$this.AccessibleName"), String)
Me.Anchor = CType(resources.GetObject("$this.Anchor"),
System.Windows.Forms.AnchorStyles)

If you notice each of the "$this" values is part of a larger string being
passed to the resources variable. The resource variable is a
ResourceManager, it is reading values out the frmMain.resx file, which is
your a Resources file. The frmMain.resx is compiled into your executable so
at runtime you do not see an actual resx file with the program. Resources
files are used as part of Internationalization to change the language used
to display the form. For example an English version of the form & a German
version of the form.

The inclusion of the resources as you showed is controlled by the
Form.Localizable property set to True. Then you can change the Form.Language
property to design your form in English, German or other language you user
is expecting to see.

Note "$this" will still be included in the resx file when Form.Localizable =
False, however you should see view references to it in your VB.NET code, as
the designer uses it to store values, that are otherwise hard to persist,
such as bitmaps.

Hope this helps
Jay
 
Hi, Jay

Thanks for giving me the nuts and bolts of origin of '$this'. You are
definite a black belt level guru. Could I contact you directly, once I
have some questions about .NET. Please advise - thanks,

jason ji
 
Jason,
I normally do not respond to private emails, its better to ask your question
in the public newsgroup as this way I or someone else will answer. Later if
someone else wants to know the answer they are able to find the answer also.

For others reading this, I normally use http://groups.google.com to search
the newsgroups when I am trying to find previously posted information.

Thanks for understanding
Jay
 
Back
Top