안녕하세요
그레이프시티 입니다.
우선 새롭게 저희 그레이프시티 제품을 사용해 주셔서 감사드립니다.
기본적으로 아래의 페이지를 통해서 데모를 설치하시고 다양한 예제들을 보실수 있습니다.
https://www.grapecity.co.kr/componentone-winform#demo
여기에는 코드까지 같이 포함되어 있기 때문에 어렵지 않게 적용해 보실수 있을것 같습니다.
이제 셀에 이미지를 추가하는 방법에 대하여 안내해 드리겠습니다.
셀에 이미지를 추가하기 위해서는 아래와 같이 SetCellIamge 방법을 사용하시면 됩니다.
// Set image in cell (3,6)
c1FlexGrid1.SetCellImage(3, 6, Image.FromFile("master.png"));
// Set image in cell range (12,6) to (14, 6)
C1.Win.C1FlexGrid.CellRange cr;
cr = c1FlexGrid1.GetCellRange(12, 6, 14, 6);
cr.Image = Image.FromFile("amex.jpg");
// Display image without text
c1FlexGrid1.Rows[3].ImageAndText = false;
좀더 자세한 설명은 아래의 링크를 참고해 주시기 바랍니다.
https://www.grapecity.com/componentone/docs/win/online-flexgrid/cell-basic-operations.html
또는 DrawCell을 이용해 직접 이미지를 추가하는 방법도 있습니다.
아래의 예제를 한번 참고해봐 주시기 바랍니다.
public partial class SampleProject: Form
{
Image img1, img2, img3, img4;
private void AuditLogViewer_Load(object sender, EventArgs e)
{
object information = Resources.ResourceManager.GetObject("information");
img1 = (Image)information;
object Warning = Resources.ResourceManager.GetObject("warning");
img2 = (Image)Warning;
object critical = Resources.ResourceManager.GetObject("critical");
img3 = (Image)critical;
object unspecified = Resources.ResourceManager.GetObject("unspecified");
img4 = (Image)unspecified;
}
private void grdAuditLogs_OwnerDrawCell(object sender, OwnerDrawCellEventArgs e)
{
if (e.Col == 2)
{
e.DrawCell(C1.Win.C1FlexGrid.DrawCellFlags.Background | C1.Win.C1FlexGrid.DrawCellFlags.Border);
var width = (int)e.Graphics.MeasureString(e.Text, e.Style.Font).Width;
var img1_x = e.Bounds.X + width + 10;
var img2_x = e.Bounds.X + width + 10;
var img3_x = e.Bounds.X + width + 10;
var img4_x = e.Bounds.X + width + 10;
var img1_loc = new Point(img1_x, e.Bounds.Y + img1.Height - 18);
var img2_loc = new Point(img2_x, e.Bounds.Y + img2.Height - 18);
var img3_loc = new Point(img3_x, e.Bounds.Y + img3.Height - 18);
var img4_loc = new Point(img4_x, e.Bounds.Y + img4.Height - 18);
if (grdAuditLogs[e.Row, grdAuditLogs.Cols["Severity"].Index].ToString() == "Information")
e.Graphics.DrawImage(img1, img1_loc);
if (grdAuditLogs[e.Row, grdAuditLogs.Cols["Severity"].Index].ToString() == "Warning")
e.Graphics.DrawImage(img2, img2_loc);
if (grdAuditLogs[e.Row, grdAuditLogs.Cols["Severity"].Index].ToString() == "Critical")
e.Graphics.DrawImage(img3, img3_loc);
if (grdAuditLogs[e.Row, grdAuditLogs.Cols["Severity"].Index].ToString() == "Unspecified")
e.Graphics.DrawImage(img4, img4_loc);
e.Graphics.DrawString(e.Text, e.Style.Font, Brushes.Black, e.Bounds.Location);
e.Handled = true;
}
}
추가적으로 궁금하신 사항은 다시 문의해 주시기 바랍니다.
감사합니다.
그레이프시티 드림.