.Net Framework Standard/Component
[Devexpress] BandedGridView에서 Header가 너무 긴 경우 Caption 표시
달빛에취하다
2024. 1. 15. 16:30
private void AdditionalBMController_CustomDrawBandHeader(object sender, DevExpress.XtraGrid.Views.BandedGrid.BandHeaderCustomDrawEventArgs e)
{
if (e.Band != null )
{
if (e.Band.ReallyVisible == false || e.Band.HasChildren == false)
return;
if (e.Graphics.ClipBounds.Width > e.Info.CaptionRect.Width)
return;
e.Info.Caption = "";
e.Painter.DrawObject(e.Info);
System.Drawing.Drawing2D.GraphicsState state = e.Graphics.Save();
Rectangle r = e.Info.CaptionRect;
StringFormat sf = new StringFormat();
sf.FormatFlags = sf.FormatFlags;// | StringFormatFlags.NoWrap;
sf.Alignment = StringAlignment.Center;
int gwidth = Convert.ToInt32(e.Graphics.ClipBounds.Width);
int gx = Convert.ToInt32(e.Graphics.ClipBounds.X);
int heigh = (int)e.Info.CaptionRect.Height;
int width = e.Info.CaptionRect.Width > gwidth ? gwidth : e.Info.CaptionRect.Width;
int sX = e.Info.CaptionRect.Width + e.Info.CaptionRect.Location.X - (int)e.Graphics.ClipBounds.X;
int x = e.Info.CaptionRect.Location.X > gx ? e.Info.CaptionRect.Location.X : sX < gx ? sX : gx;
int y = (int)e.Info.CaptionRect.Location.Y;
r.X = x;
r.Y = y;
r.Width = width;
r.Height = heigh;
e.Handled = true;
e.Graphics.DrawString(e.Band.Caption, e.Appearance.Font, e.Appearance.GetForeBrush(e.Cache), r, sf);
e.Graphics.Restore(state);
}
}
긴 Band Header가 있는 경우 화면에 Caption이 표시되지 않는 문제 처리