8

私はC#が初めてです。form1のボタンをクリックすると、新しいフォーム(form2)を表示しようとしています。

これは私のコードです。

        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 SliceEngine
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
        private void button5_Click(object sender, EventArgs e)
        {   
            Form2 form2 = new Form2();
            form2.ShowDialog();            
         }
    }
}

エラーショー

型または名前空間名 'Form2' が見つかりませんでした (using ディレクティブまたはアセンブリ参照がありませんか?)

これはform2の私のコードです。

    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 SliceEngine
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {

        }
    }
}

form2 については、デザイン インターフェイスを作成しただけです。

Java を使用するときに知っていることは、最初にオブジェクトを宣言することだけです。私はこれのために何をすべきですか?

4

9 に答える 9

5

タイプミスがない限り、コードが失敗する理由はわかりません。あなたと同じコードを試してみましたが、私のマシンではうまくいきました。

    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 winapp
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            private void button1_Click(object sender, EventArgs e)
            {
                Form2 frm2 = new Form2();
                frm2.ShowDialog();
            }
        }




    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 winapp
    {
        public partial class Form2 : Form
        {
            public Form2()
            {
                InitializeComponent();
            }
        }
    }
于 2012-08-02T03:00:17.827 に答える
1

form1 では、Form2 のコンストラクターを使用しています。

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

に変更すると

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

あなたは大丈夫なはずです。

于 2012-08-02T02:07:28.107 に答える
1

あなたのコードは、 のコンストラクターがないと主張Form1しています。

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

次のようにする必要があります。

 public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
于 2012-08-02T02:08:09.300 に答える
1

このコードを試してください.....

private void button1_Click(object sender, EventArgs e)
{
       Form2 frm2 = new Form2();
       {
          frm2.ShowDialog();
       }
}
于 2017-07-28T06:02:05.487 に答える