我在C#中有GUI項目。主窗口類的定義是這樣的:視覺工作室設計師視圖無法獲得正確的形式
FormView.cs文件
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 */
}
}
FormViewInit.cs文件
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.
}
}
}
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
}
}
問題是:爲什麼我得到一個窗體,大小錯誤,沒有元素,當我試圖查看FormView。 CS在設計視圖在Visual Studio 2010?
我強烈建議你從一個「正常」的形式開始,然後一點一點地把它變成了什麼你需要,每次檢查你是否打破了設計師。 – 2012-04-18 14:44:39
是的,這聽起來像我的InitializeComponet類沒有正確設置您的窗體及其子控件的正確值(聽起來像你甚至錯過了代碼,將您的元素添加到您的窗體)。設計師可以爲你做很多這項工作。 – 2012-04-18 18:06:33
代碼,它爲表單設置了正確的值,並且它的子項設置正確。我可以運行應用程序,並按預期工作。我唯一不能在設計器視圖中查看我的應用程序。 – cheshie 2012-04-18 22:52:45