버튼설정을 하면 기본적인 이미지가 딸려오게 Custom Controls 을 제작
Custom Controls을 만들면 도구상자에 등록되어 간편하게 기본컨트롤 이용하는거 처럼 이용할수 있다
만들기시작!
화면에서
이미지리스트를 추가해서 사용할 이미지를 등록한다
소스
public partial class ImageButton : System.Windows.Forms.Button 을 상속받는다
위와같이 변경해주면 속성값을 변경해줄수도 있음
여기서 컨트롤 기본값을 설정해도 된다 ㅋ
설정할수 있는 속성을 하나 만든다 기본값으로 OK 주었기 때문에 컨트롤 기본이지는 OK 이미지다
위와같이 설정 해놓으면 컨트롤 사용할때
아래와 같이 사용할수 있다.
이걸로 초간단 Custom Controls 만들기 끝~
[
Browsable(true)
]
public partial class ImageButton : System.Windows.Forms.Button
{
public enum EnumImage {OK , CANCEL , DELETE , UPDATE , MOVE }
public ImageButton()
{
InitializeComponent();
this.ImageList = this.imageListMain;
this.TextImageRelation = TextImageRelation.ImageBeforeText;
string imagekey = Enum.GetName(typeof(EnumImage), ImageType);
this.ImageKey = imagekey;
}
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
}
[DefaultValue(EnumImage.OK)]
public EnumImage ImageType
{
set;
get;
}
}
ImageList도 귀찮으면
이미지를 넣은다음에 OnPaint 이벤트에서 저렇게 해주면 끝~
protected override void OnPaint(PaintEventArgs pe)
{
string imagekey = Enum.GetName(typeof(EnumImage), ImageType);
this.Image = (Image)Properties.Resources.ResourceManager.GetObject(imagekey);
base.OnPaint(pe);
}'C#.NET' 카테고리의 다른 글
| [ErrorProvider]폼 유효성에 대한 오류 아이콘 표시 (0) | 2010.03.03 |
|---|---|
| 초간단 숫자 앞에 0 채우기 (0) | 2010.02.25 |
| 초간단 DataGridView 사용법 (추가중…) (0) | 2010.02.22 |
| [.Resx 리소스 , Resources]리소스 액세스 (3) | 2010.02.10 |
| [Process]외부프로그램 실행 / 익스플로어실행 (0) | 2010.02.08 |
| 초간단한 Login Form 만들기 (0) | 2010.02.04 |
| [Form Loading]폼로딩 보여주기 (0) | 2010.02.03 |
| virtual 메소드 (0) | 2010.01.27 |
| 예외 처리try catch 및 Throw (0) | 2010.01.12 |
| [문자열 , byte , 바이트 ]간단한 문자열 자르기 (0) | 2010.01.12 |