简体   繁体   English

InitializeComponent 在当前上下文中不存在,使用 Mono C# 编译器

[英]InitializeComponent does not exist in the current context, using Mono C# compiler

I am using mcs version 2.10.8.1 in Ubuntu 12.04, I have the following code:我在 Ubuntu 12.04 中使用 mcs 版本 2.10.8.1,我有以下代码:

using System;
using System.Drawing;
using System.Windows.Forms;

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

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.ShowDialog();

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                string fileName;
                fileName = dlg.FileName;
                MessageBox.Show(fileName);
            }
        }
    }
}

I compile using the command我使用命令编译

$ mcs source_code.cs -r:System.Windows.Forms.dll -r:System.Drawing.dll 

And I receive the error我收到错误

source_code.cs(11,13): error CS0103: The name `InitializeComponent' does not exist in the current context
Compilation failed: 1 error(s), 0 warnings

I've seen many answers to this question in cases using Visual Basic;在使用 Visual Basic 的情况下,我已经看到了这个问题的许多答案; I would like to know what I should do to solve this problem.我想知道我应该怎么做才能解决这个问题。 Thanks.谢谢。

Was your C# code originally created in Visual Studio?您的 C# 代码最初是在 Visual Studio 中创建的吗? If so, then you'll probably have a Form1.Designer.cs file as well as the file containing the code that you've written by hand.如果是这样,那么您可能会有一个Form1.Designer.cs文件以及包含您手工编写的代码的文件。 You need to include the file in the command line.您需要在命令行中包含该文件。

If this isn't C# code originally created in Visual Studo, you may not even have an InitializeComponent method... but in that case you'll need more code to do anything useful in your form (like creating the button and hooking up its Click event).如果这不是最初在 Visual Studo 中创建的 C# 代码,则您甚至可能没有InitializeComponent方法……但在这种情况下,您将需要更多代码来在表单中执行任何有用的操作(例如创建按钮并连接其Click事件)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当前上下文中不存在名称“InitializeComponent”(c#,xamarin) - The name 'InitializeComponent' does not exist in the current context(c#,xamarin) 当前上下文中不存在“ InitializeComponent” - 'InitializeComponent' does not exist in the current context c# 不包含“InitializeComponent”的定义,名称“controlName”在当前上下文中不存在 - c# does not contain a definition for "InitializeComponent" and name "controlName" does not exist in current context 在c#web应用程序中使用泛型时,initializecomponent()在当前上下文中不存在 - initializecomponent() don't exist in current context while using generics in c# web application 当前上下文错误中不存在InitializeComponent - InitializeComponent does not exist in the current context error 名称InitializeComponent在当前上下文中不存在 - The name InitializeComponent does not exist in the current context 当前上下文中不存在“InitializeComponent”和“_FrameViews” - The 'InitializeComponent' and '_FrameViews' does not exist in the current context WPF应用程序中的当前上下文中不存在名称“InitializeComponent” - The name 'InitializeComponent' does not exist in the current context in WPF application 组件在当前上下文中不存在-C# - Component does not exist in the current context - C# C# - 当前上下文中不存在该名称 - C# - The name does not exist in the current context
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM