Ahsan Hussain
Ahsan Hussain

Reputation: 982

not able to access my new form in any of the other form or class

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();
        }

Upvotes: 2

Views: 3113

Answers (3)

Premashis Poddar
Premashis Poddar

Reputation: 1

Check all forms namespace should be same in form.designer.cs if not select the namespace right click > refactor>Rename as main form namespace.

Upvotes: 0

Thomas Levesque
Thomas Levesque

Reputation: 292555

frmUserBio is defined in the SurveyBuilder.Forms namespace, so you need to add a using for it:

using SurveyBuilder.Forms;

Upvotes: 0

Dmitrii Bychenko
Dmitrii Bychenko

Reputation: 186803

You should mention your form namespace in using

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

or use the full form:

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

Upvotes: 2

Related Questions