سؤال

I have a multi project solution in VB.Net. I have a custom made form, which other forms can inherit. It is in a seperate project called "CustomForm", there are no special graphical effects, it is the same as a generic Windows Form, just handles closing differently. I have a project called "TestProject1" with a form named Form1 in it, which inherits CustomForm. In the third project "TestManager", you can add an instance of Form1 from TestProject1, and set its ownership to TestManager. I have this setup with the following code inside TestManager:

Public Shared Sub CreateForm(ByVal frm As CustomForm.CustomForm)

    frm.Owner = TestManager.TestManager

    frm.Show()
End Sub

However I get the following error: 'Form1' is a type in 'TestProject1' and cannot be used as an expression.

EDIT: More Details:

Form1 has nothing on it at the moment. Imagine TestManager as a desktop, where a form from another project is added to it. TestManager references TestProject1, and used the code: CreateForm(TestProject1.Form1) which utilizes the above method. Now form1 references and inherits CustomForm. This error is displayed the moment I enter the code, so I cannot even build the project.

هل كانت مفيدة؟

المحلول

Due to my own stupidity, I oversaw such a simple error. I did not create an object or instance of the form, which was the issue. Simply had to add 'New' to the line.

CreateForm(New TestProject1.Form1())

نصائح أخرى

Just a little help here. An internship at my office was having this issue. The reason: he was overloading the constructor (wich was ok) but he did NOT create a default constructor.

It seems that if you want to use a class of your own without sending parameters, it's ok, but if you want to have more than one constructor and you DO NOT add the default constructor (the one without parameters) then this error will rise.

He was using VS 2010 Pro

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top