jNumpad
은 숫자를 입력받을 수 있는 콘트롤입니다. jButtons 과 jLabels 을 조합하여 만든 것으로 기존 Visual Studio 에는 없었던 콘트롤입니다.
Visual Studio에서는 jNumpad는 무조건 보이도록 되어 있지만, Visible
속성이 디폴트로 false
로 되어 있어서, Windows CE 디바이스에서는 보이지 않습니다. 이것을 보이도록 하려면 Visible
속성을 true
로 변경하면 됩니다.
일반적으로 평소에는 jNumpad를 감추고 있다가, 필요할 때 Visible
속성을 true
로 만들면 마치 팝업창처럼 표시되어 숫자를 입력받을 수 있습니다.
또는 Open 메소드 함수 이용해서 불러낼 수 있습니다.
각각의 버튼속성을 모두 조정할 수 있습니다.
여러분의 입맛에 맞게 각각의 버튼을 커스터마이징 할 수 있습니다.
여러개의 버튼을 동시에 선택해서 색상등을 변경할 수 있습니다.
ValueDisplay
속성은 맨위에 있는 입력된 숫자를 표시하는 창에 대한 속성입니다.
public virtual void Open(Action<string> handleResult, string initialValue, string title, bool clearOnFirstEdit) public virtual void Open(Action<string> handleResult, string initialValue, string title)
handleResult
- 사용자가 Enter버튼을 눌렀을때 실행할 callback 함수
initialValue
- numpad'의 ValueDisplay 속성에 표시할 초기값
title
- numpad의 상단에 표시할 text
clearOnFirstEdit
- True로하면 최초 입력시, 처음에 표시된 초기값을 지웁니다. false로 하면 초기값에 추가하여 값을 입력할 수 있습니다.
Open
메소드 함수는 jNumpad를 표시합니다. Enter 버튼을 누르면 jNumpad 를 종료하고, handleResult
콜백 함수를 호출합니다. Cancel 을 누르면 handleResult
콜백 함수를 호출하지 않고 곧바로 종료합니다.
아래 있는 예제는 2개의 jLabel
을 표시하고 있습니다. 하나는 정수 입력을 위한 _intLabel
이고, 다른 하나는 소수입력을 위한 _floatLabel
입니다. 이 둘은 같은 jNumpad
인 _numpad
를 호출하게 됩니다. 라벨을 클릭(터치)하면 Click
이벤트 핸들러가 콜되고, 이 핸들러에서는 _numpad
의 Open
매소드 함수를 호출합니다.
유저가 Enter버튼을 클릭(터치)하면, 정수 입력시에는 SetIntLabel
메소드 함수를 호출하고, 실수 입력시에는 SetFloatLabel
메소드 함수를 호출합니다.
private void SetIntLabel(string numpadResult) { _intLabel.Text = int.Parse(numpadResult).ToString(); // Input is finished, re-enable decimal point _numpad.DotButton.Enabled = true; } private void _intLabel_Click(object sender, EventArgs e) { // Disable decimal point for integers _numpad.DotButton.Enabled = false; // Open the numpad. Call SetIntLabel when the Enter button is pressed. _numpad.Open(SetIntLabel, _intLabel.Text, "Integer"); } private void SetFloatLabel(string numpadResult) { _floatLabel.Text = float.Parse(numpadResult).ToString(); } private void _floatLabel_Click(object sender, EventArgs e) { // Open the numpad. Call SetFloatLabel when the Enter button is pressed. _numpad.Open(SetFloatLabel, _intLabel.Text, "Floating Point"); }