0

Form1.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Wizard
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        protected override void OnLoad(EventArgs e)
        {
            this.CurrentPage = page11;
            this.btnCancel.Enabled = false;
            this.btnFinish.Enabled = false;

            base.OnLoad(e);
        }

        private IPagePanel _currentPage;

        public IPagePanel CurrentPage
        {
            get
            {
                return _currentPage;
            }
            set
            {
                _currentPage = value;
            }
        }

        private void page11_Load(object sender, EventArgs e)
        {

        }

        private void btnNext_Click(object sender, EventArgs e)
        {
            if (this.CurrentPage == page11)
            {
                this.CurrentPage = (IPagePanel)page21;
                page21.Visible = false;
                page21.Visible = true;
                btnCancel.Enabled = true;
            }
            //else
            //{
            //    this.CurrentPage = _thirdPageWizardPanel;
            //    _secondPageWizardPanel.Visible = false;
            //    _thirdPageWizardPanel.Visible = true;
            //    _cmdNext.Enabled = false;
            //    _cmdFinish.Enabled = true;
            //}
        }
    }
}

上面显示的代码是我想要创建的向导。Page1 和 Page2 是我使用的用户控制页面。

IPagePanel.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Wizard
{
    public interface IPagePanel
    {
    }
}

用户控件 Page1 和 Page2 位于 2 个单独的命名空间中。

namespace Page1
{
    partial class Page1
    {
        /// <summary> 
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary> 
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Component Designer generated code

        /// <summary> 
        /// Required method for Designer support - do not modify 
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.lblDescription = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // lblDescription
            // 
            this.lblDescription.AutoSize = true;
            this.lblDescription.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lblDescription.Location = new System.Drawing.Point(228, 114);
            this.lblDescription.Name = "lblDescription";
            this.lblDescription.Size = new System.Drawing.Size(65, 20);
            this.lblDescription.TabIndex = 0;
            this.lblDescription.Text = "Page 1";
            // 
            // Page1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.Controls.Add(this.lblDescription);
            this.Name = "Page1";
            this.Size = new System.Drawing.Size(547, 278);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Label lblDescription;
    }
}

错误信息:

错误 1 ​​无法将类型“Page1.Page1”隐式转换为“Wizard.IPagePanel”。存在显式转换(您是否缺少演员表?) 21 32 向导

4

1 回答 1

1

实施和IPagePanel_Page1Page2

Page1.cs

public partial class Page1 : IPagePanel
{
    //Your implementation here
    ...
}

Page2.cs

public partial class Page2 : IPagePanel
{
    //Your implementation here
    ...
}
于 2012-10-22T06:35:25.680 回答