C# 运行时隐藏/显示按钮
我需要你在c#和一些图形问题上的帮助:我正在开发一个非常简单的应用程序。有一个名为DeltaPregView的唯一表单、一个名为DeltaPregController的表单控制器和一个包含项目主要部分的类: 主要类别:C# 运行时隐藏/显示按钮,c#,.net,winforms,windows-mobile-6,C#,.net,Winforms,Windows Mobile 6,我需要你在c#和一些图形问题上的帮助:我正在开发一个非常简单的应用程序。有一个名为DeltaPregView的唯一表单、一个名为DeltaPregController的表单控制器和一个包含项目主要部分的类: 主要类别: using System; using System.Linq; using System.Collections.Generic; using System.Windows.Forms; namespace deltaPreg { static class Progr
using System;
using System.Linq;
using System.Collections.Generic;
using System.Windows.Forms;
namespace deltaPreg
{
static class Program
{
[MTAThread]
static void Main()
{
//create the view
DeltaPregView view = new DeltaPregView();
//link the view to the APP
Application.Run(view);
//initialize the controller of the APP
DeltaPregController controller = new DeltaPregController(view);
}
}
}
类的视图:
using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace deltaPreg
{
public partial class DeltaPregView : Form
{
public DeltaPregView()
{
InitializeComponent();
}
public void init()
{
prova.Visible = false;
}
}
}
以及视图的控制器:
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
namespace deltaPreg
{
class DeltaPregController
{
#region variables
private DeltaPregView view;
#endregion
public DeltaPregController(DeltaPregView view)
{
this.view = view;
//start the reading process
start();
}
private void start()
{
view.init();
}
}
}
我想隐藏名为“prova”的按钮,但我的程序中没有任何更改。我是winforms管理的新手,提前谢谢你 问题是在调用
DeltaPregView
中的init
函数之前打印表单
解决此问题的一种方法是更换这些线路:
//link the view to the APP
Application.Run(view);
//initialize the controller of the APP
DeltaPregController controller = new DeltaPregController(view);
致:
好的,它是这样工作的……嗯……但这意味着我不能在运行时修改表单?我的意思是:创建表单后如何修改表单并使更改可见?我必须以某种方式重新打印表单吗?@superpuccio您可以在运行时更改表单,而无需重新打印,但请确保它发生在
Application.Run(view)之后代码>已被调用。您在按钮实际存在之前更改了它的属性。
//initialize the controller of the APP
DeltaPregController controller = new DeltaPregController(view);
//link the view to the APP
Application.Run(view);