在运行时隐藏/显示按钮

时间:2014-02-19 10:54:46

标签: c# .net winforms windows-mobile-6

我需要你对c#和一些图形问题的帮助:我正在开发一个非常简单的应用程序。有一个名为DeltaPregView的独特形式,一个名为DeltaPregController的形式的控制器和一个包含项目Main的类:

主类:

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管理层的新手,非常感谢你。

1 个答案:

答案 0 :(得分:1)

问题是您在调用init中的DeltaPregView功能之前打印表单。

解决这个问题的一种方法是更换这些行:

    //link the view to the APP
    Application.Run(view);
    //initialize the controller of the APP
    DeltaPregController controller = new DeltaPregController(view);

要:

    //initialize the controller of the APP
    DeltaPregController controller = new DeltaPregController(view);
    //link the view to the APP
    Application.Run(view);