C# 这种OOP转换可能吗
我正在开发一个实用类来构建一些常用函数 其中一个函数尝试自定义窗口窗体属性。 该函数接受一个参数,该参数应为窗体引用变量,然后自定义其布局 问题是窗口窗体是不同的对象类型,例如Form1、Form2等 因此,我无法确定应该在函数中使用什么对象类型。C# 这种OOP转换可能吗,c#,oop,C#,Oop,我正在开发一个实用类来构建一些常用函数 其中一个函数尝试自定义窗口窗体属性。 该函数接受一个参数,该参数应为窗体引用变量,然后自定义其布局 问题是窗口窗体是不同的对象类型,例如Form1、Form2等 因此,我无法确定应该在函数中使用什么对象类型。 e、 g.公共静态无效SetFormatAttribute(参考???targetForm) 代码如下: void btn_show_Click(object sender, EventArgs e) { this.p
e、 g.公共静态无效SetFormatAttribute(参考???targetForm) 代码如下:
void btn_show_Click(object sender, EventArgs e)
{
this.pnl_ShowForms.Controls.Clear();
int tag = Convert.ToInt32( (sender as Button).Tag);
switch (tag)
{
case 1:
Form1 frm1 = new Form1();
Utilities.SetFormAttributes(ref frm1);
this.pnl_ShowForms.Controls.Add(frm1);
frm1.Show();
break;
case 2:
Form2 frm2 = new Form2();
Utilities.SetFormAttributes(ref frm2);
this.pnl_ShowForms.Controls.Add(frm2);
frm2.Show();
break;
case 3:
Form3 frm3 = new Form3();
Utilities.SetFormAttributes(ref frm3);
this.pnl_ShowForms.Controls.Add(frm3);
frm3.Show();
break;
}
}
namespace WFA_ShowFormsInPanel
{
public static class Utilities
{
public static void SetFormAttributes(ref ??? targetForm)
{
{
targetForm.FormBorderStyle = FormBorderStyle.None;
targetForm.Dock = DockStyle.Fill;
targetForm.WindowState = FormWindowState.Maximized;
targetForm.TopLevel = false;
}
}
}
}
所有表单都从基类继承,因此在
setFormatAttributes
中使用此类型
作为旁注,由于
Form
是一个对象(因此是一个引用类型),因此不需要使用ref
将其作为参数传递。所有表单都继承自基类,因此在setFormatAttributes
中使用此类型
作为旁注,由于
Form
是一个对象(因此是一个引用类型),因此不需要使用ref
将其作为参数传递。所有表单都继承自基类,因此在setFormatAttributes
中使用此类型
作为旁注,由于
Form
是一个对象(因此是一个引用类型),因此不需要使用ref
将其作为参数传递。所有表单都继承自基类,因此在setFormatAttributes
中使用此类型
作为旁注,由于Form
是一个对象(因此是一个引用类型),因此不需要使用ref
将其作为参数传递。将方法更改为
public static class Utilities
{
public static void SetFormAttributes(Form targetForm)
{
{
targetForm.FormBorderStyle = FormBorderStyle.None;
targetForm.Dock = DockStyle.Fill;
targetForm.WindowState = FormWindowState.Maximized;
targetForm.TopLevel = false;
}
}
}
由于所有Windows窗体都将从窗体继承
将方法更改为
public static class Utilities
{
public static void SetFormAttributes(Form targetForm)
{
{
targetForm.FormBorderStyle = FormBorderStyle.None;
targetForm.Dock = DockStyle.Fill;
targetForm.WindowState = FormWindowState.Maximized;
targetForm.TopLevel = false;
}
}
}
由于所有Windows窗体都将从窗体继承
将方法更改为
public static class Utilities
{
public static void SetFormAttributes(Form targetForm)
{
{
targetForm.FormBorderStyle = FormBorderStyle.None;
targetForm.Dock = DockStyle.Fill;
targetForm.WindowState = FormWindowState.Maximized;
targetForm.TopLevel = false;
}
}
}
由于所有Windows窗体都将从窗体继承
将方法更改为
public static class Utilities
{
public static void SetFormAttributes(Form targetForm)
{
{
targetForm.FormBorderStyle = FormBorderStyle.None;
targetForm.Dock = DockStyle.Fill;
targetForm.WindowState = FormWindowState.Maximized;
targetForm.TopLevel = false;
}
}
}
既然所有Windows窗体都将从
窗体继承
为什么要引用?(添加填充以满足最小注释大小要求)我已经测试了建议的代码,它可以工作。然而,为什么ref不是必需的?我是OOP新手,我想如果我想更改原始对象,我必须通过ref。任何解释这一点的点击或链接都将不胜感激。为什么?(添加填充以满足最小注释大小要求)我已经测试了建议的代码,它可以工作。然而,为什么ref不是必需的?我是OOP新手,我想如果我想更改原始对象,我必须通过ref。任何解释这一点的点击或链接都将不胜感激。为什么?(添加填充以满足最小注释大小要求)我已经测试了建议的代码,它可以工作。然而,为什么ref不是必需的?我是OOP新手,我想如果我想更改原始对象,我必须通过ref。任何解释这一点的点击或链接都将不胜感激。为什么?(添加填充以满足最小注释大小要求)我已经测试了建议的代码,它可以工作。然而,为什么ref不是必需的?我是OOP新手,我想如果我想更改原始对象,我必须通过ref。任何解释这一点的点击或链接都将不胜感激。