I want to use a GUI made with C# WinForms in Python.
Here are the versions I am using:
Python: 3.12 Pythonnet: 3.0.5 For C#, I used Visual Studio 2022. When creating the project, I selected "WinForms" and wrote the code as follows:
namespace WinFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("hello");
}
public static void ShowForm()
{
Application.Run(new Form1());
}
}
}
After building the solution in C#, I copied the DLL file from the Debug folder into the Python project folder.
For Python, I am using Visual Studio Code.
import clr
import os
def test():
clr.AddReference(r"./WinFormsApp1.dll")
from WinFormsApp1 import Form1
Form1.ShowForm()
if __name__ == "__main__":
test()
from WinFormsApp1 import Form1
As shown in the image, this part is not recognized.
What should I do?
"./WinFormsApp1.dll". Why do you think the dll is in that folder. Have you tried to write some Python code to see what that folder"."is, and checking to make sure the dll is there. Try reading a text file from where you expect it to be. If you can get the full name of a file from a relative name in Python, see what you see