2011-05-16 3 views
0

나는 여러 사용자 컨트롤로 키오스크 시스템을 만들었으며 colddrinks 사용자 컨트롤에있는 버튼을 사용하여 hotdrinks 사용자 컨트롤을 연결해야합니다.사용자 컨트롤 연결

다음 코드를 사용하면 colddrinks 아래에 두 개의 사용자 컨트롤이 모두 표시되고 hotdrinks가 표시됩니다. 먼저 colddrinks를 숨기고 다음에 hotdrinks를 표시해야합니다. 여기에 자녀와 부모 연결을 사용해야한다고 생각하지만 어떻게해야하는지 모릅니다. 도와주세요.

OrderTakingMenu ordertakingmenu; 
HotDrinks hotDrinks; 

public UserControl currentPanel; 

public ColdDrink(OrderTakingMenu ordertakingmenuIn) 
{ 
    InitializeComponent(); 
    this.Location = new System.Drawing.Point(5, 100); 
    ordertakingmenu = ordertakingmenuIn; 
} 

private void btnHotDrinks_Click(object sender, EventArgs e) 
{ 
    removePreviousPanel(); 
    currentPanel = new HotDrinks(ordertakingmenu); 
    this.Controls.Add(currentPanel); 
} 

private void removePreviousPanel() 
{ 
    this.Controls.Remove(currentPanel); 
} 

답변

0

Visible 속성을 사용합니다. 먼저 양식에 두 개의 사용자 정의 컨트롤을 추가하고 서로 겹치게하십시오 (둘 다 같은 위치, 같은 크기).

public ColdDrink(OrderTakingMenu ordertakingmenuIn) 
{ 
    InitializeComponent(); 
    this.Location = new System.Drawing.Point(5, 100); 
    ordertakingmenu = ordertakingmenuIn; 
    coldDrinksPanel.Visible = true; 
    hotDrinksPanel.Visible = false; 
} 

private void btnHotDrinks_Click(object sender, EventArgs e) 
{ 
    hotDrinksPanel.Visible = true; 
    coldDrinksPanel.Visible = false; 
} 
+0

나는이 회신을 시도했지만 작동하지 않으며 "개체 참조가 개체의 인스턴스로 설정되지 않았습니다"라는 오류 메시지가 표시됩니다. 도와 주셔서 감사 드리며 아이디어를주십시오. – Leo

+0

두 개의 사용자 정의 컨트롤을 모두 디자이너에 추가하십시오. 그것은 그들을 창조 할 것이다. InitializeComponent()를 호출하기 전에 액세스하지 않았는지 확인하십시오. – David

관련 문제