如何解决此错误“在当前上下文中不存在”。 [英] How can I solve this error "does not exist in current context".

查看:234
本文介绍了如何解决此错误“在当前上下文中不存在”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

单击登录按钮后,我想隐藏登录表单并显示登录确认表单以及包含侧栏的第二个表单。当我点击按钮时,我收到当前上下文中不存在错误。



Upon clicking a login button I would like to hide the login form and display a login confirmation form along with a second form containing a sidebar. When I click the button I receive a "does not exist in current context" error.

public partial class Dashboad : Form
{
    public Dashboad()
    {
        InitializeComponent();
    }

    private int imageNumber = 1;

    public void LoadNextLoad()
    {
        if (imageNumber == 10)
        {
            imageNumber = 1;
        }
        slider.ImageLocation = string.Format(@"images/{0}.jpg", imageNumber);
        imageNumber++;
    }

    private void slideTimer_Tick(object sender, EventArgs e)
    {
        LoadNextLoad();
    }

    private void Dashboad_Load(object sender, EventArgs e)
    {

    }
    private void LeftPanel_Paint(object sender, PaintEventArgs e)
    {

    }
    private void BodyPanel_Paint(object sender, PaintEventArgs e)
    {

    }
}

public partial class loginForm : Form
{
    public loginForm()
    {
        InitializeComponent();
    }
    private void btnlogin_Click(object sender, EventArgs e)
    {
        this.Hide();
        SideBarMenu menu = new SideBarMenu();
        menu.TopLevel = false;
        menu.FormBorderStyle = FormBorderStyle.None;
        menu.Dock = DockStyle.Fill;
        LeftPanel.Controls.Clear();
        LeftPanel.Controls.Add(menu);
        menu.Visible = true;
    }
}





我的尝试:





What I have tried:

public partial class Dashboad : Form
{
    public Dashboad()
    {
        InitializeComponent();
    }

    private int imageNumber = 1;

    public void LoadNextLoad()
    {
        if (imageNumber == 10)
        {
            imageNumber = 1;
        }
        slider.ImageLocation = string.Format(@"images/{0}.jpg", imageNumber);
        imageNumber++;
    }

    private void slideTimer_Tick(object sender, EventArgs e)
    {
        LoadNextLoad();
    }

    private void Dashboad_Load(object sender, EventArgs e)
    {

    }
    private void LeftPanel_Paint(object sender, PaintEventArgs e)
    {

    }
    private void BodyPanel_Paint(object sender, PaintEventArgs e)
    {

    }
    public void Dothis()
    {        
        SideBarMenu menu = new SideBarMenu();
        menu.TopLevel = false;
        menu.FormBorderStyle = FormBorderStyle.None;
        menu.Dock = DockStyle.Fill;
        LeftPanel.Controls.Clear();
        LeftPanel.Controls.Add(menu);
        menu.Visible = true;
    }
}

public partial class loginForm : Form
{
    public loginForm()
    {
        InitializeComponent();

    }

    Dashboad call = new Dashboad();

    private void btnlogin_Click(object sender, EventArgs e)
    {
        this.Hide();
        call.Dothis();
    }
}

推荐答案

查看错误消息;它的完整形式是这样的:

Look at the error message; it's full form is like this:
Error	<No>	The name '<property or methodname>' does not exist in the current context	d:\documents\aa backed up\my projects\generaltesting\GTForms\frmmain.cs	<Line>	<Col>	GTForms

它基本上意味着我找不到那个名字的东西

所以看看属性或方法名称,如果给你,看看它告诉你的文件它发现了问题,转到它告诉你问题所在的行号。



或者只需双击错误信息,VS就会把你带到那里。



仔细看看。看看上面的线条。名称拼写是否正确?是否可以在定义的类之外访问?



我们不能为您做到这一点:我们不知道您使用的控件,定义它们的位置或它们包含的内容。所以从错误信息开始,看看你能找到什么!

And it basically means "I can't find anything of that name"
So look at the property or method name if gives you, look in the file it tells you it found the problem in, go to the line number it tells you the problem is on.

Or just double click the error message and VS will take you right there.

Look at it closely. Check out the lines immediately above. Is the name spelled correctly? Is it accessible outside the class it is defined in?

We can't do that for you: we have no idea what controls you are using, where they are defined, or what they contain. So start with the error message, and see what you can find out!


这篇关于如何解决此错误“在当前上下文中不存在”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆