I apologize ahead of time for my lack of terminology and understanding, I am very new to .NET and Visual Studio.
I am on Windows 7 64 Bit in Visual Studio Community 2019 Version 16.10.4 making a Console Application for .NET 5.0 using Visual Basic.
I am trying to use the Windows.Forms.Form object and make a little window pop-up and ask the user to select an item from a ListBox. But so far I have not been successful in adding System.Windows.Forms to my project.
I tried Imports System.Windows.Forms
but that gave the warning "Namespace or type specified in the Imports 'System.Windows.Forms' doesn't contain any public member or cannot be found.".
I went to Project -> Add COM Reference -> "System_Windows_Forms" (Version 2.0)
That reference has a warning: "Failed to create the wrapper assembly for type library {215d64d2-031c-33c7-96e3-61794cd1ee61}. Type library 'System_Windows_Forms' was exported from a CLR assembly and cannot be re-imported as a CLR assembly."
I heard that adding the .dll directly can fix that, so I removed the COM reference and went to Project -> Add Project Reference -> Browse -> "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Windows.Forms.dll"
When I searched for Forms.dll I found about 10 files so I just picked the one that looked most correct. After that, I could use the objects in my script and Visual Studio could autocomplete the properties and functions of the objects. But when I actually went into the debugger and tried to run the script, I get the error:
System.IO.FileNotFoundException
HResult=0x80070002
Message=Could not load file or assembly 'System.Drawing.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
Source=System.Windows.Forms
StackTrace:
at System.Windows.Forms.Control..ctor(Boolean autoInstallSyncContext)
at System.Windows.Forms.Control..ctor()
at System.Windows.Forms.ListControl..ctor()
at System.Windows.Forms.ListBox..ctor()
at GetNovel.Program.DetermineNovel()
Here is my sub that causes the error:
Sub DetermineNovel()
Dim Novels As Object = {{"Moon's Labyrinth", "ML", True, 262, 362}, {"Keyboard Immortal", "KI", False, 254, 254}}
Dim SelectBox As New Windows.Forms.ListBox
Dim i As Long
For i = LBound(Novels) To UBound(Novels)
SelectBox.Items.Add(Novels(i, 0))
Next i
Dim NovelSelect As New Windows.Forms.Form
NovelSelect.Controls.Add(SelectBox)
NovelSelect.Text = "Select Novel:"
NovelSelect.Show()
End Sub