title: VB.NET How do I get the name of a BackgroundImage?
body: <p>I have a function that will give the new form a BackgroundImage:</p>
  
  <pre><code>    Public Shared WaitForNet As Image = My.Resources.WFN
      Public Shared WaitForDB As Image = My.Resources.WFS
      Public Shared Function GetWaitFormBG(code As String) As Image
      Dim img As Image = Nothing
  
      Select Case code
          Case "Net"
              img = WaitForNet
          Case "DB"
              img = WaitForDB
      End Select
  
      Return img
  End Function
  </code></pre>
  
  <p>And in the Sub I have:</p>
  
  <pre><code>Public Shared Sub FrmWaitLoad(ByVal R As String)
      Dim WF As New WaitForm
  
      WF.Tag = GetWaitFormBG(R)
      WF.Show()
  End Sub
  </code></pre>
  
  <p>In WaitForm Load I have:</p>
  
  <pre><code>Private Sub WaitForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
      BackgroundImage = Tag
          If Tag = "Net" Then
          Do Until Net = True
              Application.DoEvents()
          Loop
      End If
  
      If Tag = "DB" Then
  
          T = 5
  
          Timer1.Interval = 60000
          Timer1.Enabled = True
  
          Do Until DB = True
              Application.DoEvents()
          Loop
  
          Timer1.Stop()
          Close()
      End If
  End Sub
  </code></pre>
  
  <p>But I get an error message:</p>
  
  <p>"System.InvalidCastException: 'Overload resolution failed because no Public '=' can be called with these arguments:
      'Public Shared Operator =(a As String, b As String) As Boolean':
          Argument matching parameter 'a' cannot convert from 'Bitmap' to 'String'.'"</p>
  
  <p>If I change it from "If Tag = "Net" Then" to "If Tag = My.Resources.WFN Then" then I get "'Operator '=' is not defined for type 'Bitmap' and type 'Bitmap'.'" error</p>
  
  <p>What I need is the actual name of the BackgroundImage</p>
  
  <p>Thanks for the help</p>