의 WinForm :
alt text http://i36.tinypic.com/2r26a77.pngWinForm에서 CheckBox 컨트롤을 처리하는 가장 좋은 방법은 무엇입니까?
코드 :
using System;
using System.Windows.Forms;
namespace DemoApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
groupBox2.Enabled = checkBox1.Checked;
}
private void button1_Click(object sender, EventArgs e)
{
SaveSetings();
}
private void SaveSetings()
{
Properties.Settings.Default.UserName = textBox1.Text;
Properties.Settings.Default.pass = textBox2.Text;
Properties.Settings.Default.userproxy = checkBox1.Checked;
Properties.Settings.Default.proxy = textBox3.Text;
Properties.Settings.Default.proxy_port = textBox4.Text;
Properties.Settings.Default.Save();
}
//private void Form1_Load(object sender, EventArgs e)
//{
// checkBox1.Refresh();
// groupBox2.Enabled = checkBox1.Checked;
//}
}
}
u는 그 반대의 경우도 마찬가지 groupbox1를 활성화해야합니다 선택하거나 할 때입니다 내가 "프록시 사용"확인란이 코드에서 볼 수 있듯이. 문제는 그룹 컨트롤 1이 선택되지 않은 경우에도 체크 컨트롤이 "user.config"에서 설정을로드 할 때입니다. 이 상황을 처리하는 한 가지 방법은이 작업을 수행하고 내 응용 프로그램이 더 dinamic 만들기 위해 다른이 폼로드 이벤트 즉
groupBox2.Enabled = checkBox1.Checked;
에서 컨트롤에 확인하는 것입니다? 여러 가지 컨트롤이 단일 폼에있는 상황이있을 수 있기 때문에 내가 이것을 묻는 이유는 혼란 스러울 것이라고 생각합니다.
코드는 방법으로 조금 최적화 할 수 있습니다 ... 설정 { 경우 (_useProxy = 값!) { _useProxy = 값; SetControlStates(); } } 은 모두 UseProxy의 설정 도구에 필요합니다. :) – mike