/* 안녕하세요 저는 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;
}
}
}
}
이것은 어디에도 표시되지 않습니다. 정말 책을 읽을 필요가 있습니다. Winforms 프로그래밍은 시행 착오에서 배울 수있는 것이 아닙니다. –