/* こんにちは、Visual Studio で初めての C# アプリケーションを作成しようとしています。メインでクラスとそのクラスのインスタンスを作成しました。フォームのクリック イベント内でそのインスタンスのメンバーをクエリしようとしているだけですが、インスタンス名が現在のコンテキストに存在しないことがわかります。ここに私のコードがあります。*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace WindowsFormsApplication10
{
public class character // this is my class
{
public bool hair_black;
}
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
character deviljin = new character(); // instance of my class
deviljin.hair_black = true; // initiating a member of the instance
}
}
}
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 WindowsFormsApplication10
{
public partial class Form1 : Form
{
int cs1 = 0,cs2=0;
public Form1()
{
InitializeComponent();
public void pictureBox1_Click(object sender, EventArgs e)
{
flowLayoutPanel1.Visible = true;
if (deviljin.hair_black == true) // trying to access instance member
{ // but getting deviljin does not
// exist in the current context
pictureBox28.Visible = false;
}
}
}
}