2014-02-19 63 views
0

我需要您對c#和一些圖形問題的幫助:我正在開發一個非常簡單的應用程序。有一種獨特的形式叫DeltaPregView,名爲DeltaPregController形式的控制器和一個類,它包含該項目的主要:運行時隱藏/顯示按鈕

主類:

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(); 
     } 
    } 
} 

我想到h找到叫做「prova」的按鈕,但是我的程序沒有任何變化。我是winforms管理的新手,提前感謝你。

回答

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); 
+1

好吧,是這樣工作的... ... Mmh的,但這意味着我可以」在運行時修改表單?我的意思是:如何在創建窗體後修改窗體並使其可見?我需要以某種方式重新打印表格嗎? – superpuccio

+0

@superpuccio您可以在運行時更改它,而不用重新打印,但確保它在'Application.Run(view);'被調用後發生。 在實際存在之前,您更改了該按鈕的屬性。 – etaiso