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:
Rich 2011-03-18 14:17:33 +00:00
parent bf0bae229e
commit 6cd97c36ce

View File

@ -55,30 +55,36 @@ namespace Volian.Controls.Library
{ {
if (CopyOptionChanged != null) CopyOptionChanged(sender, args); if (CopyOptionChanged != null) CopyOptionChanged(sender, args);
} }
//[XmlElement("MyBorders")]
//[Browsable(false)] [XmlElement("MyBorders")]
//[EditorBrowsable(EditorBrowsableState.Never)] [Browsable(false)]
//public string MyBorderDetailString [EditorBrowsable(EditorBrowsableState.Never)]
//{ public string MyBorderDetailString
// get {
// { get
// return _MyBorderDetail.ToString(); {
// } return MyBorders.ToString();
// set }
// { set
// if (value != null) {
// _MyBorderDetail = VlnBorderDetail.Get(value); if (value != null)
// else _MyBorders = VlnBorders.Get(value);
// _MyBorderDetail = null; else
// } _MyBorders = null;
//} }
//private VlnBorderDetail _MyBorderDetail; }
//[XmlIgnore] private VlnBorders _MyBorders;
//public VlnBorderDetail MyBorderDetail [XmlIgnore]
//{ public VlnBorders MyBorders
// get { return _MyBorderDetail; } {
// set { _MyBorderDetail = value; } get
//} {
if (_MyBorders == null)
_MyBorders = new VlnBorders(GridLinePattern.Single, Rows.Count, Cols.Count);
return _MyBorders;
}
set { _MyBorders = value; }
}
private ItemInfo _MyItemInfo; private ItemInfo _MyItemInfo;
public ItemInfo MyItemInfo public ItemInfo MyItemInfo
{ {
@ -660,7 +666,8 @@ namespace Volian.Controls.Library
// draw the RTF text // draw the RTF text
if (e.Bounds.Width > 0 && e.Bounds.Height > 0) 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; _rtf.Rtf = rtfText;
CellRange cr = GetMergedRange(e.Row, e.Col); CellRange cr = GetMergedRange(e.Row, e.Col);
cr.UserData = _rtf.Height; cr.UserData = _rtf.Height;
@ -668,7 +675,6 @@ namespace Volian.Controls.Library
int hDiff = e.Bounds.Height - _rtf.Height; int hDiff = e.Bounds.Height - _rtf.Height;
if (hDiff < 0) 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; Rows[e.Row].Height = _rtf.Height + 4;
AdjustGridControlSize(); AdjustGridControlSize();
hDiff = 0; hDiff = 0;
@ -709,29 +715,47 @@ namespace Volian.Controls.Library
} }
// and draw border last // and draw border last
e.DrawCell(DrawCellFlags.Border); //e.DrawCell(DrawCellFlags.Border);
// This can be used to draw more specific borders // 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 // we're done with this cell
e.Handled = true; 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; Graphics graphics =e.Graphics;
int y1 = rectangle.Top; Rectangle bounds = e.Bounds;
int x2 = rectangle.Right - 1; int row = e.Row;
int y2 = rectangle.Bottom - 1; 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) if (row == 0)
graphics.DrawLine(Pens.Black, x1, y1, x2, y1); graphics.DrawLine(VlnBorders.LinePen(lineTop, bColor), x1, y1, x2, y1);
if (col == 0) if (col == 0)
graphics.DrawLine(Pens.Black, x1, y1, x1, y2); graphics.DrawLine(VlnBorders.LinePen(lineLeft, bColor), x1, y1, x1, y2);
graphics.DrawLine(Pens.Black, x1, y2, x2, y2); graphics.DrawLine(VlnBorders.LinePen(lineBottom, bColor), x1, y2, x2, y2);
graphics.DrawLine(Pens.Black, x2, y1, x2, y2); graphics.DrawLine(VlnBorders.LinePen(lineRight, bColor), x2, y1, x2, y2);
// Double line attribute the Bottom of the first row // 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); // graphics.DrawLine(Pens.Black, x1, y2-2, x2, y2-2);
} }
#endregion //Grid Initialize #endregion //Grid Initialize
@ -930,8 +954,6 @@ namespace Volian.Controls.Library
/// </summary> /// </summary>
public void AdjustGridControlSize() public void AdjustGridControlSize()
{ {
//Console.WriteLine("AdjustGridControlSize");
//Volian.Base.Library.vlnStackTrace.ShowStackLocal("AdjustGridControlSize", 3);
if (Parent is GridItem ? (Parent as GridItem).Initializing : false ) return; if (Parent is GridItem ? (Parent as GridItem).Initializing : false ) return;
int difW = this.Width - this.ClientSize.Width; int difW = this.Width - this.ClientSize.Width;
int difH = this.Height - this.ClientSize.Height; int difH = this.Height - this.ClientSize.Height;
@ -1077,7 +1099,6 @@ namespace Volian.Controls.Library
} }
private void AdjustCellHeightWidth(int r, int c) private void AdjustCellHeightWidth(int r, int c)
{ {
Console.WriteLine("AdjustCellHeightWidth");
StepRTB trtb = new StepRTB(); StepRTB trtb = new StepRTB();
string tstr = null; string tstr = null;
bool dummyCharWidth = false; bool dummyCharWidth = false;
@ -2003,6 +2024,7 @@ namespace Volian.Controls.Library
this.Cols.Insert(newcol); this.Cols.Insert(newcol);
// set new column width to same width as column from where it was inserted // set new column width to same width as column from where it was inserted
this.Cols[newcol].Width = this.Cols[newcol + 1].Width; this.Cols[newcol].Width = this.Cols[newcol + 1].Width;
MyBorders.InsertColumn(newcol);
this.AdjustMergedColumns(newcol, true, false); this.AdjustMergedColumns(newcol, true, false);
this.AdjustGridControlSize(); this.AdjustGridControlSize();
} }
@ -2014,6 +2036,7 @@ namespace Volian.Controls.Library
this.Cols.Add(1); this.Cols.Add(1);
else else
this.Cols.Insert(colidx + 1); this.Cols.Insert(colidx + 1);
MyBorders.InsertColumn(colidx);
// set new column width to same width as column from where it was inserted // set new column width to same width as column from where it was inserted
this.Cols[colidx + 1].Width = this.Cols[colidx].Width; this.Cols[colidx + 1].Width = this.Cols[colidx].Width;
this.AdjustMergedColumns(colidx + 1, false, false); 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 // 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 = (Rows[newrow + 1].Height == -1) ? Rows.DefaultSize : Rows[newrow + 1].Height;
//this.Rows[newrow].Height = this.Rows[newrow + 1].Height; //this.Rows[newrow].Height = this.Rows[newrow + 1].Height;
MyBorders.InsertRow(newrow);
this.AdjustMergedRows(newrow, true, false); this.AdjustMergedRows(newrow, true, false);
this.AdjustGridControlSize(); this.AdjustGridControlSize();
} }
@ -2041,6 +2065,7 @@ namespace Volian.Controls.Library
// set new row Height to same heidht as row from where it was inserted // 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 = (Rows[rowidx].Height == -1) ? Rows.DefaultSize : Rows[rowidx].Height;
//this.Rows[rowidx + 1].Height = this.Rows[rowidx].Height; //this.Rows[rowidx + 1].Height = this.Rows[rowidx].Height;
MyBorders.InsertRow(rowidx + 1);
this.AdjustMergedRows(rowidx + 1, false, false); this.AdjustMergedRows(rowidx + 1, false, false);
this.AdjustGridControlSize(); this.AdjustGridControlSize();
} }
@ -2125,6 +2150,7 @@ namespace Volian.Controls.Library
mergedRow = false; mergedRow = false;
} }
} }
MyBorders.DeleteRows(strow, cnt);
this.AdjustGridControlSize(); this.AdjustGridControlSize();
} }
@ -2155,6 +2181,7 @@ namespace Volian.Controls.Library
mergedCol = false; mergedCol = false;
} }
} }
MyBorders.DeleteColumns(stcol, cnt);
this.AdjustGridControlSize(); this.AdjustGridControlSize();
} }