2010-03-14 2 views

답변

1

이 시도 : 그 후,이 같은 내 코드 뒤에 모습입니다

컨트롤 디자이너

public class CustomPanelDesigner : ControlDesigner 
{ 

    public override bool AllowResize 
    { 
     get { return false; } 
    } 

} 

사용자 지정 컨트롤

[Designer(typeof(CustomPanelDesigner))] 
public class CustomPanel : WebControl 
{ 

    public CustomPanel() : base(HtmlTextWriterTag.Div) { } 

    [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] 
    public override Unit Width 
    { 
     get { return new Unit("100px"); } 
     set { throw new NotSupportedException(); } 
    } 

    [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] 
    public override Unit Height 
    { 
     get { return new Unit("100px"); } 
     set { throw new NotSupportedException(); } 
    } 

} 
+0

완벽. 나는 이것을 찾고 있었다. 속성 창에 대해서도 잘 작동하지만 @slugster와 같은 생성자에서 너비와 높이를 설정해야한다. – wonde

1

System.Web.UI.WebControls.WebControl에서 사용자 정의 컨트롤을 상속하면 height 및 width 속성을 무시하고 setter에서 아무 작업도 수행 할 수 없습니다.

그래서 내가, 새 컨트롤을 생성 zzz 그것을 불러 System.Web.UI.WebControls.WebControl에 System.Web.UI.UserControl 로부터 상속을 변경했습니다.

public partial class zzz : WebControl 
{ 
    public zzz() 
    { 
     base.Height = new Unit(100, UnitType.Pixel); 
     base.Width = new Unit(150, UnitType.Pixel); 
    } 

    public override Unit Height 
    { 
     get { return base.Height; } 
     set { } 
    } 

    public override Unit Width 
    { 
     get { return base.Width; } 
     set { } 
    } 
} 
+0

@Slugster을 - 글쎄, 나는이 방법을 시도했다. 그러나 여전히 통제 지금 필요한 것은 고정 된 크기로 디자인 타임에는 속성 창에서 크기를 조정할 수 없습니다. 가져와. – wonde

관련 문제