Mech_Engineer Mech_Engineer - 6 months ago 37x Question FolderBrowserDialog warning

I searched for a proper way to use the

but i'm getting a warning and I don't get why.

I added the folderbrowserdialog on my form in the design window.

Then I used this code, like I found on various websites.

If (FolderBrowserDialog1.ShowDialog() = DialogResult.OK) Then
tb_CopyToPath.Text = FolderBrowserDialog1.SelectedPath
End If

And visual studio is giving me following warning.


Access of shared member, constant member, enum member or nested type
through an instance; qualifying expression will not be evaluated.

What do I need to change to remove this warning?


That warning is because you're inside a Form (which has a DialogResult property) and you're using DialogResult enumeration (of which OK is a Shared member). Compiler is telling you that you're accessing a Shared member (OK, in this case) through an instance (DialogResult property value, which by case is also of type DialogResult).

AFAIK it has been solved long time ago but if you're using an old VB.NET compiler then you may still need to specify full type name (which will disambiguate between property and type name):

FolderBrowserDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK

Side comment about naming convention: pick a proper name for FolderBrowserDialog1 and do not use underscore in identifiers...