2

私は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
    }
}

問題は、Visual Studio 2010 のデザイン ビューで FormView.cs を表示しようとすると、サイズが正しくなく、要素がないフォームが表示されるのはなぜですか?

4

3 に答える 3

1

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

于 2012-04-18T14:15:14.403 に答える
0

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

于 2012-04-18T14:18:47.297 に答える
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);
    }
}

FormView.csではなく、デザイナーモードのFormViewInit.csファイルで表示する必要があります

于 2012-04-19T11:20:32.253 に答える