わかりました、あなたが遭遇している問題についての写真が見えます。
まず、メソッドに ref を追加する必要はありません (さらに、より適切な命名を検討してください)。既に参照されているオブジェクトです
public void beheerToegang(Form frm)
{
}
次に、カスタム フォームの例 (テストされていないコード) からメソッドをそのまま使用できます。
frmInkomsteBlad form1 = new frmInkomsteBlad();
beheerToegang(form1);
次に、次のようにアクセスします。
public void beheerToegang(Form frm)
{
string formTitle = frm.Text;
}
ただし、カスタム フォーム frmInkomsteBlad で定義されたプロパティ/フィールドにアクセスすることはできません。例:
public class frmInkomsteBlad : Form{
public string CustomString{get;set;} // this property cannot be accessed
}
ただし、これを回避する方法があります。まず、型キャストを使用します。
public void beheerToegang(Form frm)
{
if(frm is frmInkomsteBlad){
frmInkomsteBlad typeCastedForm = (frmInkomsteBlad)frm;
string customString = typeCastedForm.CustomString;
}
}
上記の例は悪い習慣ですが、実装は簡単です。より良いプラクティスを重視する場合は、代わりにインターフェイスを使用することを検討してください。例:
public interface ICustomForm{
string Title{get;set;}
string CustomString{get;set;}
object CustomObject{get;set;}
}
frmInkomsteBlad フォームに実装します。
public class frmInkomsteBlad : Form, ICustomForm{
public string Title{
get{
return this.Text;
}
set{
this.Text = value;
}
}
//other implementation here
}
次に、次のように使用できます。
public void beheerToegang(ICustomForm frm)
{
string customString = frm.CustomString;
string title = frm.Title;
object customObject = frm.CustomObject;
}