2012-04-18 15 views
2

私はC#でGUIプロジェクトを持っています。メインウィンドウクラスの定義は次のようになります。ビジュアルスタジオデザイナーのビューが正しいフォームを取得できません

FormView.csがFormViewInit.csがFormViewEventHandlers.cs質問が

using System; 
using System.IO; 
using System.Windows.Forms; 

namespace RssReader 
{ 
    partial class FormView 
    { 

     private void Quit_Click(object sender, EventArgs e) 
     { 
      if (MessageBox.Show("Do you really want to quit?", "Exit", MessageBoxButtons.YesNo) 
       == DialogResult.Yes) 
       Application.Exit(); 
     } 

     // here goes event handler functions 
    } 
} 

されたファイル

namespace RssReader 
{ 
    partial class FormView 
    { 
     private void InitializeComponent() 
     { 
      this.MainContainer = new System.Windows.Forms.SplitContainer(); 
      this.Items = new System.Windows.Forms.TreeView(); 
      this.Message = new System.Windows.Forms.WebBrowser(); 
      this.MainMenu = new System.Windows.Forms.MenuStrip(); 
      this.File = new System.Windows.Forms.ToolStripMenuItem(); 
      this.AddFeed = new System.Windows.Forms.ToolStripMenuItem(); 
      this.Separator = new System.Windows.Forms.ToolStripSeparator(); 
      this.Quit = new System.Windows.Forms.ToolStripMenuItem(); 

      // the only component in this file is InitializeComponent method 
      // all, what it does is just defining items on the form 
      // and initializing it, i.e., creating instances, assign names etc. 
     } 
    } 
} 

ファイル

using System; 
using System.Collections.Generic; 
using System.Runtime.InteropServices; 
using System.Windows.Forms; 

namespace RssReader 
{ 
    partial class FormView : Form, IView 
    { 
     private SplitContainer MainContainer; 
     private TreeView Items; 
     private MenuStrip MainMenu; 
     private ToolStripMenuItem File; 
     private ToolStripMenuItem AddFeed; 
     private ToolStripSeparator Separator; 
     private ToolStripMenuItem Quit; 
     private WebBrowser Message; 

     /* some methods here which are implementing some kind of logic */ 
    } 
} 

ファイルなぜFormViewを表示しようとしているのですか?ビジュアルスタジオ2010のデザインビューでcs?

+0

私は強く、その後何に少しずつそれを変更し、あなたが「正常な」フォームからスタート示唆しますあなたはデザイナーを壊したかどうか毎回チェックする必要があります。 –

+0

あなたのInitializeComponetクラスがあなたのフォームとその子コントロールの適切な値を適切に設定していないように聞こえます(あなたのフォームに要素を追加するコードがないように思えます)。デザイナーは、あなたのために多くのこの作業を行うことができます。 –

+0

コードは、フォームの正しい値を設定し、その子が正しく設定されています。私は、アプリケーションを実行することができ、期待どおりに動作します。唯一のことはデザイナーの視点でアプリケーションを見ることができないことです。 – cheshie

答えて

0

は、要素の定義をFormViewInit.csファイル(InitializeComponentメソッドを持つファイル)に移動することで解決されます。

ファイルがどのように見えてから問題になるか。どのファイルが今になります

public partial class FormView 
{ 
    private System.ComponentModel.IContainer components = null; 

    private SplitContainer MainContainer; 
    private TreeView Items; 
    private MenuStrip MainMenu; 
    private ToolStripMenuItem File; 
    private ToolStripMenuItem AddFeed; 
    private ToolStripSeparator Separator; 
    private ToolStripMenuItem Quit; 
    private ContextMenuStrip ContextMenu; 
    private ToolStripMenuItem RemoveItem; 
    private WebBrowser Message; 

    protected void InitializeComponent() 
    { 
     this.components = new System.ComponentModel.Container(); 
     this.MainContainer = new System.Windows.Forms.SplitContainer(); 
     this.Items = new System.Windows.Forms.TreeView(); 
     this.Message = new System.Windows.Forms.WebBrowser(); 
     this.MainMenu = new System.Windows.Forms.MenuStrip(); 
     this.File = new System.Windows.Forms.ToolStripMenuItem(); 
     this.AddFeed = new System.Windows.Forms.ToolStripMenuItem(); 
     this.Separator = new System.Windows.Forms.ToolStripSeparator(); 
     this.Quit = new System.Windows.Forms.ToolStripMenuItem(); 
     this.ContextMenu = new System.Windows.Forms.ContextMenuStrip(this.components); 
     this.RemoveItem = new System.Windows.Forms.ToolStripMenuItem(); 
     this.MainContainer.Panel1.SuspendLayout(); 
     this.MainContainer.Panel2.SuspendLayout(); 
     this.MainContainer.SuspendLayout(); 
     this.MainMenu.SuspendLayout(); 
     this.ContextMenu.SuspendLayout(); 
     this.SuspendLayout(); 

     /* there goes properties initializing, like setting names, sizes etc */ 
    } 

    // Added just in case 

    protected override void Dispose(bool disposing) 
    { 
     if (disposing && (components != null)) 
     { 
      components.Dispose(); 
     } 
     base.Dispose(disposing); 
    } 
} 

あなたはデザイナーモードFormViewInit.csファイルで表示すべきではなく、FormView.csは

1

FormViewにコンストラクタがありますか?はいの場合は、InitializeComponent()メソッドが呼び出されますか?

+0

クラスFormViewはpublicコンストラクタを持ち、メソッドInitializeComponent()を呼び出しています。 – cheshie

+0

これはデフォルトのコンストラクタですか? 'public FormView(){...}'? –

+0

これはpublicのようですFormView(){/ *ここにいくつかのロジックがあります*/this.InitializeComponent(); } – cheshie

0

フォームはpublicクラスである必要があります。

+0

3つのファイルすべてにpublicキーワードを追加しましたが、それは役に立たなかった。 – cheshie

関連する問題