2

i am new in C#, i am working on a project using C# in Visual Studio, i have already 8 to 9 forms in my project, today when i created one more form named frmUserBio, it's not accessible in other forms, whenever namespace of the forms and program.cs file is same, every thing looks perfect but i am still not able to access it, writting below some code of my program.cs and frmUserBio form Code,

Program.cs Code:

namespace SurveyBuilder
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

frmUserBio.cs code:

namespace SurveyBuilder.Forms
{
    public partial class frmUserBio : Form
    {
        public frmUserBio()
        {
            InitializeComponent();
        }

        private void frmUserBio_Load(object sender, EventArgs e)
        {
         //
        }                   
    }
}

i am want to open frmUserBio form in another form using

frmUserBio frm = new frmUserBio();
frm.Show();

but i am not able to access frmUserBio Form here....

and the form in which i want to access frmUserBio is name frmUserList, it's code is given below

frmUserList.cs Code:

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;
using System.Data.SqlClient;

namespace SurveyBuilder
{
    public partial class frmUserList : Form
    {
        public frmUserList()
        {
            InitializeComponent();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }
4

3 回答 3

2

您应该在使用时提及您的表单命名空间

using SurveyBuilder.Forms; // <- Namespace where frmUserBio class is declared
...
frmUserBio frm = new frmUserBio();
frm.Show();

或使用完整的表格

SurveyBuilder.Forms.frmUserBio frm = new SurveyBuilder.Forms.frmUserBio();
frm.Show();
于 2013-08-13T11:46:24.473 回答
0

如果没有选择命名空间右键单击 > 重构 > 重命名为主表单命名空间,请检查 form.designer.cs 中的所有表单命名空间应该相同。

于 2014-09-14T12:52:52.553 回答
0

frmUserBio是在命名空间中定义的SurveyBuilder.Forms,所以你需要using为它添加一个:

using SurveyBuilder.Forms;
于 2013-08-13T11:47:07.187 回答