무료 Grid 소개
Winform에서 사용할 수 있는 무료 Grid가 있어서 소개합니다.
DOWNLOAD
아래 링크에서 다운로드를 합니다. sourcegrid-v2.0.0.zip을 다운로드하고 압축을 해제합니다.
GitHub - siemens/sourcegrid: sourcegrid
GitHub - siemens/sourcegrid: sourcegrid
sourcegrid. Contribute to siemens/sourcegrid development by creating an account on GitHub.
github.com
VISUAL STUDIO에 추가하기
- Visual Studio를 실행시켜, 새로운 Winform을 하나 만듭니다.
새로운 프로젝트를 만든다. - 윈폼이 생성되면, 아래와 같이 Panel을 추가하고, 라벨을 추가합니다.
- 이제 다운로드한 SourceGrid를 넣어봅시다.
도구상자를 클릭한뒤, 오른쪽 버튼을 눌러 항목선택을 선택합니다.
찾아보기를 클릭한뒤, 다운로드한 SourceGrid.dll을 선택합니다.도구상자에 SourceGrid를 추가 할수 있다. 도구상자에 SourceGrid를 추가 할수 있다. 다운받은 dll을 선택한다. - 아래와 같이 도구상자에 사용가능한 SourceGrid가 추가되었습니다.
이제 WinForm으로 Grid를 끌어다 놓을 수 있습니다.SourceGrid 컨트롤러가 추가되었다. - 중간에 있는 Grid를 새로 만든 WinForm에 끌어다 놓습니다.
Grid를 끌어다 놓으면 참조에 SourceGrid.dll이 자동으로 추가됩니다.
Grid 사용하기
끌어다 놓은 Grid를 선택하시고, 속성에서 이름을 아래와 같이 설정합니다.
그런 다음 만든 폼의 빈 곳을 더블클릭하면 아래와 같이 Form1_Load 함수가 자동으로 생성이 됩니다.
private void Form1_Load(object sender, EventArgs e)
{
InitGridCell();
SetGrid();
}
InitGridCell함수는 Cell의 속성을 정의해 주는 함수로, 해당 내용을 작성해 보도록 하겠습니다.
우선 파란색 Header를 위한 cell 전역 변수를 선언합니다.
SourceGrid.Cells.Views.Cell cell_header1;
SourceGrid.Cells.Views.Cell cell_header2;
InitGridCell() 함수를 아래와 같이 작성합니다.
private void InitGridCell()
{
cell_header1 = new SourceGrid.Cells.Views.Cell();
cell_header1.BackColor = Color.FromArgb(130, 179, 237);
cell_header1.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter;
cell_header2 = new SourceGrid.Cells.Views.Cell();
cell_header2.BackColor = Color.FromArgb(150, 199, 237);
cell_header2.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter;
}
SetGrid 함수를 작성하기 전에, GridColumHeadSet() 함수를 작성하여 Header를 먼저 표시합니다.
private void GridColumHeadSet()
{
int iGridLineHead = 0;
// Grid 칼럼 설정
grid_person.ColumnsCount = 4;
grid_person.FixedRows = 1;
grid_person.FixedColumns = 1;
grid_person.Rows.Insert(iGridLineHead);
grid_person[iGridLineHead, 0] = new SourceGrid.Cells.ColumnHeader("ID");
grid_person[iGridLineHead, 0].View = cell_header1;
grid_person[iGridLineHead, 1] = new SourceGrid.Cells.ColumnHeader("Name");
grid_person[iGridLineHead, 1].View = cell_header2;
grid_person[iGridLineHead, 2] = new SourceGrid.Cells.ColumnHeader("Phone");
grid_person[iGridLineHead, 2].View = cell_header2;
grid_person[iGridLineHead, 3] = new SourceGrid.Cells.ColumnHeader("Sex");
grid_person[iGridLineHead, 3].View = cell_header2;
}
SetGrid() 함수를 아래와 같이 작성합니다.
public void SetGrid()
{
GridColumHeadSet();
int iGridLine = 1;
grid_person.Rows.Insert(iGridLine);
grid_person[iGridLine, 0] = new SourceGrid.Cells.Cell("1");
grid_person[iGridLine, 1] = new SourceGrid.Cells.Cell("JYJHS 1");
grid_person[iGridLine, 2] = new SourceGrid.Cells.Cell("010-XXXX-XXXX");
grid_person[iGridLine, 3] = new SourceGrid.Cells.Cell("F");
iGridLine++;
grid_person.Rows.Insert(iGridLine);
grid_person[iGridLine, 0] = new SourceGrid.Cells.Cell("2");
grid_person[iGridLine, 1] = new SourceGrid.Cells.Cell("JYJHS 2");
grid_person[iGridLine, 2] = new SourceGrid.Cells.Cell("010-XXXX-XXXX");
grid_person[iGridLine, 3] = new SourceGrid.Cells.Cell("M");
AutoGridSet();
}
AutoGridSet() 함수를 작성하지 않고, 실행하면 아래와 같이 표현이 됩니다.
그럼 AutoGridSet() 함수를 작성하여, 셀간격이 자동으로 되도록 해 보겠습니다.
private void AutoGridSet()
{
// 길이 계산
grid_person.AutoSizeCells();
int basewidth = 0;
int baseheight = 0;
foreach (SourceGrid.GridColumn gcol in grid_person.Columns)
{
basewidth += gcol.Width;
}
foreach (SourceGrid.GridRow grow in grid_person.Rows)
{
baseheight += grow.Height;
}
grid_person.Height = baseheight + 2;
grid_person.Width = basewidth + 2;
this.Width = grid_person.Width + 50;
}
컴파일하신 후, 실행을 하시면 아래와 같이 표시가 됩니다.
전체 코드 첨부 합니다.
2024.04.28 - [기타] - 유틸리티 소개 HDD 사용량 확인 및 정리
유틸리티 소개 HDD 사용량 확인 및 정리
📁 HDD 사용량 확인 및 정리법이번에는 컴퓨터를 사용하면서 많은 도움이 되는 유틸리티를 소개하고자 합니다. 📁 폴더별 크기 확인컴퓨터를 사용하다 보면, 하드디스크(또는 SSD) 드라이브
rich313.tistory.com
'기타' 카테고리의 다른 글
레트로 게임보이에 Hello World 출력하기 (2) | 2024.04.28 |
---|---|
유틸리티 소개 HDD 사용량 확인 및 정리 (1) | 2024.04.28 |
아이와 함께 의왕 철도 박물관 (0) | 2024.04.27 |
암호 화폐 관련 스미싱 문자, 조심하세요! (2) | 2024.04.26 |
후쿠오카에서 우버타기 (8월 프로모션 코드 포함) (0) | 2024.04.25 |