2011-12-05 2 views
1

어떻게 TextBox의 Text 속성을 패널의 너비에 바인딩 할 수 있습니까?텍스트를 크기에 바인딩

panel1.DataBindings.Add("Text", textBox3, "Size.Width"); 

을하지만 예외

Object does not match target type. 

편집을 제기 :

나는 시도 내가 텍스트 상자의 텍스트가 변경 될 때, 패널의 폭을 변경하고 싶습니다. 크기의 값을 반환하는 재산이기 때문에,

void MakeBind() 
{ 
    Binding bind = new Binding("Width", textBox3, "Text"); 
    bind.Format += new ConvertEventHandler(bind_Format); 
    panel1.DataBindings.Add(bind); 
} 
void bind_Format(object sender, ConvertEventArgs e) 
{ 
    int i = 0; 
    int.TryParse((string)e.Value, out i); 
    e.Value = i; 
} 

또한 알고 있어야합니다, 당신이 직접 Size.Width을 변경할 수 없습니다 :

+0

''TypeConverter'] (http://msdn.microsoft.com/en-us/library/system.componentmodel.typeconverter.aspx)를'string'에서'int'로 변환하고 이 변환기를 바인딩에 사용하십시오. –

+0

질문 세부 사항을 확장하십시오 ... – Sandy

+0

@ 대니얼 어떻게합니까? – kilotaras

답변

3

시도 이 형식으로 변경할 수 없습니다. 새 너비로 새 크기를 설정하는 경우에만.

+0

어리석은 나를. 매력으로 작동합니다. 고맙습니다. – kilotaras

-1

이 시도

panel1.DataBindings.Add("Text", int.TryParse(textBox3.text), "Size.Width");

+0

-1 : 유감스럽게 생각하지만 데이터 바인딩이 어떻게 작동하는지 잘 모릅니다. –

관련 문제