用户控件C#向导创建错误

时间:2012-10-22 06:32:02

标签: c# winforms visual-studio

  

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向导

1 个答案:

答案 0 :(得分:1)

IPagePanelPage1

上实施Page2

Page1.cs

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

Page2.cs

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