2016-05-31 2 views
-4

사용자 수를 선택하는 양식이 있습니다. 나는 두 번째 형식에서 필요하지 않은 추가 텍스트 상자를 숨기려고합니다.숫자 값에 따라 텍스트 상자를 숨기는 방법은 무엇입니까?

예 사용자는 내가 그들이 그들 만이 게스트 이름을 기입해야하는 텍스트 상자 1-8되게됩니다 있도록 textbox9 및 textbox10을 숨길 싶습니다을 Form2에서 Form1에 8 명을 선택합니다.

은 무엇 비주얼 스튜디오에서이 윈도우 폼 사용하여 C 번호를 달성하는 가장 좋은 방법이 있을까요? 여기

은 예이지만, 당신이 손님의 다수를 들어

Textbox2.Visible = userChoice >= 2; 
Textbox3.Visible = userChoice >= 3; 

을 할 수있는 손님의 제한된 최대 개수를 들어

private void DisplayTextBoxs() 
    { 
     if (xBillInformationForm.dGuestNumber == 1) 
     { 
      xCustomer1Label.Visible = true; 
      xCustomer1TextBox.Visible = true; 
     } 
     if (xBillInformationForm.dGuestNumber == 2) 
     { 
      xCustomer1Label.Visible = true; 
      xCustomer1TextBox.Visible = true; 
      xCustomer2Label.Visible = true; 
      xCustomer2TextBox.Visible = true; 
     } 
     if (xBillInformationForm.dGuestNumber == 3) 
     { 
      xCustomer1Label.Visible = true; 
      xCustomer1TextBox.Visible = true; 
      xCustomer2Label.Visible = true; 
      xCustomer2TextBox.Visible = true; 
      xCustomer3Label.Visible = true; 
      xCustomer3TextBox.Visible = true; 
     } 
     if (xBillInformationForm.dGuestNumber == 4) 
     { 
      xCustomer1Label.Visible = true; 
      xCustomer1TextBox.Visible = true; 
      xCustomer2Label.Visible = true; 
      xCustomer2TextBox.Visible = true; 
      xCustomer3Label.Visible = true; 
      xCustomer3TextBox.Visible = true; 
      xCustomer4Label.Visible = true; 
      xCustomer4TextBox.Visible = true; 
     } 
    } 
+0

하여 처리 등을 추가 할 수 있습니까? (int i = 0; i jelleB

+0

Visual Studio를 사용하여 C#으로 작성되었습니다 .. – yaksushi

+0

htmlWriter ? – jelleB

답변

0

매우 반복적 인 것 같습니다/textboxes, 이것은 다루기 힘들어집니다. 동적 양식을 빌드하는 경우

+0

이것은 10 개의 텍스트 상자만큼 쉽습니다. – yaksushi

0

당신은 그들을 통해 배열 및 루프의 모든 당신이 텍스트 상자를 넣을 수 있습니다. 당신이 게시 않는 한 우리는 그래서 내 코드는 배열에있는 모든 텍스트 상자를 통해 userChoice에서 시작 간다

TextBow[10]textboxes; 
textBoxes[0] = your first textbox 
textBoxes[1] = you second textbox 

For(int i = userChoice -1; i < textBoxes.Length; i++){ 
    textBoxes[i].Visible = false; 
} 

+0

죄송합니다. 이것에 대한 코드를 아직 내 머리를 감싸려고 할 때. 오메 코드 있지만 – yaksushi

+0

내 대답 매우 반복적처럼 보인다는 그것은 윈도우의 모든 반복 – jelleB

0

반복 시도 코드 좋은 대답을 줄 수

var quantity = convert.ToInt32(xBillInformationForm.dGuestNumber); 

<table> 
    for(int i=1, i<=quantity; i++) 
    { 
     <tr> 
      <td> 
       <label id="name">Name</label> 
       <input id="address" type="text" placeholder="address" /> 
      </td> 
     </tr>   
    } 
</table> 

그리고 더 당신은 당신이 그냥 ... JQuery와에 필요한 텍스트 상자를 그릴 수 없습니다 두 개의 버튼 또는 링크 "손님을 추가"와 두 번째 형태로 "손님을 제거"와 JQuery와

+0

필요 응용 프로그램 (바탕 화면)하지 ASP.Net MVC 양식하지 않도록합니다. –

+0

이것은 ** for 루프 ** 전용입니다. 어디서든 사용할 수 있습니다. 내 말은 C# 코딩 로직이 모두 MVC, Asp.Net 또는 windows form app에서 동일하다는 의미입니다. 구문을 변경하고 어디서나이 논리를 구현해야합니다. – Riddhi

관련 문제