Added MyBorders - Custom border code
Use MyBorders in Grid_OwnerDrawCell Added Insert and Delete Row and Column support for custom borders
This commit is contained in:
parent
bf0bae229e
commit
6cd97c36ce
@ -55,30 +55,36 @@ namespace Volian.Controls.Library
|
||||
{
|
||||
if (CopyOptionChanged != null) CopyOptionChanged(sender, args);
|
||||
}
|
||||
//[XmlElement("MyBorders")]
|
||||
//[Browsable(false)]
|
||||
//[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
//public string MyBorderDetailString
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// return _MyBorderDetail.ToString();
|
||||
// }
|
||||
// set
|
||||
// {
|
||||
// if (value != null)
|
||||
// _MyBorderDetail = VlnBorderDetail.Get(value);
|
||||
// else
|
||||
// _MyBorderDetail = null;
|
||||
// }
|
||||
//}
|
||||
//private VlnBorderDetail _MyBorderDetail;
|
||||
//[XmlIgnore]
|
||||
//public VlnBorderDetail MyBorderDetail
|
||||
//{
|
||||
// get { return _MyBorderDetail; }
|
||||
// set { _MyBorderDetail = value; }
|
||||
//}
|
||||
|
||||
[XmlElement("MyBorders")]
|
||||
[Browsable(false)]
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public string MyBorderDetailString
|
||||
{
|
||||
get
|
||||
{
|
||||
return MyBorders.ToString();
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value != null)
|
||||
_MyBorders = VlnBorders.Get(value);
|
||||
else
|
||||
_MyBorders = null;
|
||||
}
|
||||
}
|
||||
private VlnBorders _MyBorders;
|
||||
[XmlIgnore]
|
||||
public VlnBorders MyBorders
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_MyBorders == null)
|
||||
_MyBorders = new VlnBorders(GridLinePattern.Single, Rows.Count, Cols.Count);
|
||||
return _MyBorders;
|
||||
}
|
||||
set { _MyBorders = value; }
|
||||
}
|
||||
private ItemInfo _MyItemInfo;
|
||||
public ItemInfo MyItemInfo
|
||||
{
|
||||
@ -660,7 +666,8 @@ namespace Volian.Controls.Library
|
||||
// draw the RTF text
|
||||
if (e.Bounds.Width > 0 && e.Bounds.Height > 0)
|
||||
{
|
||||
_rtf.Width = e.Bounds.Width - 1;
|
||||
_rtf.Width = e.Bounds.Width - 1; // This has also been -3 which matchs the rener command
|
||||
// Please add a comment if this value nedds to be changed
|
||||
_rtf.Rtf = rtfText;
|
||||
CellRange cr = GetMergedRange(e.Row, e.Col);
|
||||
cr.UserData = _rtf.Height;
|
||||
@ -668,7 +675,6 @@ namespace Volian.Controls.Library
|
||||
int hDiff = e.Bounds.Height - _rtf.Height;
|
||||
if (hDiff < 0)
|
||||
{
|
||||
Console.WriteLine("{0}, {1}, {2}, {3}, {4}", hDiff, e.Bounds.Height, _rtf.Height, e.Row, e.Col);
|
||||
Rows[e.Row].Height = _rtf.Height + 4;
|
||||
AdjustGridControlSize();
|
||||
hDiff = 0;
|
||||
@ -709,29 +715,47 @@ namespace Volian.Controls.Library
|
||||
}
|
||||
|
||||
// and draw border last
|
||||
e.DrawCell(DrawCellFlags.Border);
|
||||
//e.DrawCell(DrawCellFlags.Border);
|
||||
// This can be used to draw more specific borders
|
||||
// DrawCellBorder(e.Graphics, e.Bounds,e.Row,e.Col);
|
||||
DrawCellBorder(e);
|
||||
// we're done with this cell
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawCellBorder(Graphics graphics, Rectangle rectangle, int row, int col)
|
||||
private void DrawCellBorder(C1.Win.C1FlexGrid.OwnerDrawCellEventArgs e)
|
||||
{
|
||||
int x1 = rectangle.Left;
|
||||
int y1 = rectangle.Top;
|
||||
int x2 = rectangle.Right - 1;
|
||||
int y2 = rectangle.Bottom - 1;
|
||||
Graphics graphics =e.Graphics;
|
||||
Rectangle bounds = e.Bounds;
|
||||
int row = e.Row;
|
||||
int col = e.Col;
|
||||
CellRange cr = GetMergedRange(row, col);
|
||||
GridLinePattern lineTop = MyBorders.HorizontalLines[cr.r1,cr.c1];
|
||||
GridLinePattern lineLeft = MyBorders.VerticalLines[cr.r1, cr.c1];
|
||||
GridLinePattern lineBottom = MyBorders.HorizontalLines[cr.r2+1, cr.c2];
|
||||
GridLinePattern lineRight = MyBorders.VerticalLines[cr.r2, cr.c2+1];
|
||||
GridLinePattern lineTopLeft = cr.c1 == 0 ? GridLinePattern.None : MyBorders.HorizontalLines[cr.r1, cr.c1 - 1];
|
||||
GridLinePattern lineTopRight = cr.c2 == Cols.Count -1 ? GridLinePattern.None : MyBorders.HorizontalLines[cr.r1, cr.c2+1];
|
||||
GridLinePattern lineLeftAbove = cr.r1 == 0 ? GridLinePattern.None : MyBorders.VerticalLines[cr.r1 - 1, cr.c1];
|
||||
GridLinePattern lineLeftBelow = cr.r2 == Rows.Count -1 ? GridLinePattern.None : MyBorders.VerticalLines[cr.r2 +1, cr.c1];
|
||||
GridLinePattern lineBottomLeft = cr.c1 == 0 ? GridLinePattern.None : MyBorders.HorizontalLines[cr.r2 + 1, cr.c1 - 1];
|
||||
GridLinePattern lineBottomRight = cr.c2 == Cols.Count - 1 ? GridLinePattern.None : MyBorders.HorizontalLines[cr.r2+1, cr.c2+1];
|
||||
GridLinePattern lineRightAbove = cr.r1 == 0 ? GridLinePattern.None : MyBorders.VerticalLines[cr.r1 - 1, cr.c2];
|
||||
GridLinePattern lineRightBelow = cr.r2 == Rows.Count - 1 ? GridLinePattern.None : MyBorders.VerticalLines[cr.r2 + 1, cr.c2];
|
||||
int x1 = bounds.Left;
|
||||
int y1 = bounds.Top;
|
||||
int x2 = bounds.Right - 1;
|
||||
int y2 = bounds.Bottom - 1;
|
||||
Color bColor = Color.Blue;
|
||||
if (row == 0)
|
||||
graphics.DrawLine(Pens.Black, x1, y1, x2, y1);
|
||||
graphics.DrawLine(VlnBorders.LinePen(lineTop, bColor), x1, y1, x2, y1);
|
||||
if (col == 0)
|
||||
graphics.DrawLine(Pens.Black, x1, y1, x1, y2);
|
||||
graphics.DrawLine(Pens.Black, x1, y2, x2, y2);
|
||||
graphics.DrawLine(Pens.Black, x2, y1, x2, y2);
|
||||
graphics.DrawLine(VlnBorders.LinePen(lineLeft, bColor), x1, y1, x1, y2);
|
||||
graphics.DrawLine(VlnBorders.LinePen(lineBottom, bColor), x1, y2, x2, y2);
|
||||
graphics.DrawLine(VlnBorders.LinePen(lineRight, bColor), x2, y1, x2, y2);
|
||||
// Double line attribute the Bottom of the first row
|
||||
// if(row == 0)
|
||||
//if(cr.r2 == 0)
|
||||
// graphics.DrawLine(Pens.Black, x1, y2-2, x2, y2-2);
|
||||
}
|
||||
#endregion //Grid Initialize
|
||||
@ -930,8 +954,6 @@ namespace Volian.Controls.Library
|
||||
/// </summary>
|
||||
public void AdjustGridControlSize()
|
||||
{
|
||||
//Console.WriteLine("AdjustGridControlSize");
|
||||
//Volian.Base.Library.vlnStackTrace.ShowStackLocal("AdjustGridControlSize", 3);
|
||||
if (Parent is GridItem ? (Parent as GridItem).Initializing : false ) return;
|
||||
int difW = this.Width - this.ClientSize.Width;
|
||||
int difH = this.Height - this.ClientSize.Height;
|
||||
@ -1077,7 +1099,6 @@ namespace Volian.Controls.Library
|
||||
}
|
||||
private void AdjustCellHeightWidth(int r, int c)
|
||||
{
|
||||
Console.WriteLine("AdjustCellHeightWidth");
|
||||
StepRTB trtb = new StepRTB();
|
||||
string tstr = null;
|
||||
bool dummyCharWidth = false;
|
||||
@ -2003,6 +2024,7 @@ namespace Volian.Controls.Library
|
||||
this.Cols.Insert(newcol);
|
||||
// set new column width to same width as column from where it was inserted
|
||||
this.Cols[newcol].Width = this.Cols[newcol + 1].Width;
|
||||
MyBorders.InsertColumn(newcol);
|
||||
this.AdjustMergedColumns(newcol, true, false);
|
||||
this.AdjustGridControlSize();
|
||||
}
|
||||
@ -2014,6 +2036,7 @@ namespace Volian.Controls.Library
|
||||
this.Cols.Add(1);
|
||||
else
|
||||
this.Cols.Insert(colidx + 1);
|
||||
MyBorders.InsertColumn(colidx);
|
||||
// set new column width to same width as column from where it was inserted
|
||||
this.Cols[colidx + 1].Width = this.Cols[colidx].Width;
|
||||
this.AdjustMergedColumns(colidx + 1, false, false);
|
||||
@ -2027,6 +2050,7 @@ namespace Volian.Controls.Library
|
||||
// set new row Height to same heidht as row from where it was inserted
|
||||
this.Rows[newrow].Height = (Rows[newrow + 1].Height == -1) ? Rows.DefaultSize : Rows[newrow + 1].Height;
|
||||
//this.Rows[newrow].Height = this.Rows[newrow + 1].Height;
|
||||
MyBorders.InsertRow(newrow);
|
||||
this.AdjustMergedRows(newrow, true, false);
|
||||
this.AdjustGridControlSize();
|
||||
}
|
||||
@ -2041,6 +2065,7 @@ namespace Volian.Controls.Library
|
||||
// set new row Height to same heidht as row from where it was inserted
|
||||
this.Rows[rowidx + 1].Height = (Rows[rowidx].Height == -1) ? Rows.DefaultSize : Rows[rowidx].Height;
|
||||
//this.Rows[rowidx + 1].Height = this.Rows[rowidx].Height;
|
||||
MyBorders.InsertRow(rowidx + 1);
|
||||
this.AdjustMergedRows(rowidx + 1, false, false);
|
||||
this.AdjustGridControlSize();
|
||||
}
|
||||
@ -2125,6 +2150,7 @@ namespace Volian.Controls.Library
|
||||
mergedRow = false;
|
||||
}
|
||||
}
|
||||
MyBorders.DeleteRows(strow, cnt);
|
||||
this.AdjustGridControlSize();
|
||||
}
|
||||
|
||||
@ -2155,6 +2181,7 @@ namespace Volian.Controls.Library
|
||||
mergedCol = false;
|
||||
}
|
||||
}
|
||||
MyBorders.DeleteColumns(stcol, cnt);
|
||||
this.AdjustGridControlSize();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user