button1은 CustomPanel 하위 목록으로 들어가면서 추가 될 필드를 지정할 수 있습니다.
TableLayout 에서 Row, RowSpan 등의 속성이 추가되는 것이 궁금하여 찾아본 내용 정리입니다.

Panel 외에도 다른 컨트롤을 상속받아서도 가능합니다.
내부적으로 Dictionary 처리를 통해 값을 별도로 관리할 수 있습니다.
ProvideProperty 는 여러 개를 사용할 수 있습니다.
IExtenderProvider 를 상속받아야 하며 Setter와 Getter를 구현해주어야 사용 가능합니다.
아래는 예시 코드입니다.
using System.Collections.Generic;
using System.ComponentModel; //IExtenderProvider
using System.Windows.Forms;
namespace WindowsFormsApp6
{
//해당 이름 사용. Get, Set 구현 필수
//CustomField 이기때문에 GetCustomField(Control, 타입), SetCustomField(Control) 메소드 필요.
[ProvideProperty("CustomField", typeof(Control))]
class CustomPanel : Panel, IExtenderProvider
{
private readonly Dictionary<Control, int> fieldDict = new Dictionary<Control, int>();
public bool CanExtend(object extendee)
{
Control control = extendee as Control;
if (control == null)
{
return false;
}
//조건에 따라 전체 컴포넌트에 붙을 수 있음.
return control.Parent == this; //자식 컴포넌트에만 붙여주기
}
[DisplayName("CustomField")] //없으면 클래스명의 필드로 이름 지정됨.
public int GetCustomField(Control control)
{
if (fieldDict.TryGetValue(control, out int value))
{
return value;
}
return 0; //default value
}
public void SetCustomField(Control control, int value)
{
fieldDict[control] = value;
}
}
}
'C# > Windows Form' 카테고리의 다른 글
| [C# Windows Form] PrivateFontCollection 외부 폰트 파일 적용 (1) | 2025.11.28 |
|---|---|
| [C# Windows Form] FormBorderStyle None 에 대한 기본 클래스 (0) | 2025.11.28 |
| [C# Windows Form] Custom Button Class - 이미지 버튼 생성 (hover, press, normal, focus) (0) | 2025.11.27 |
| [C# Windows Form] 섬네일 만들기 (ListView, ListBox) (0) | 2025.11.17 |
| [C# Windows Form] ZipFile 다루기 - 압축 및 해제 (0) | 2025.10.06 |