Dispose RTF in OwnerDraw
Added Properties and Methods for UnEven Selection
This commit is contained in:
parent
2876ad911a
commit
c3cc1f3417
@ -311,7 +311,8 @@ namespace Volian.Controls.Library
|
|||||||
|
|
||||||
private void Grid_OwnerDrawCell(object sender, C1.Win.C1FlexGrid.OwnerDrawCellEventArgs e)
|
private void Grid_OwnerDrawCell(object sender, C1.Win.C1FlexGrid.OwnerDrawCellEventArgs e)
|
||||||
{
|
{
|
||||||
RTF _rtf = new RTF();
|
using (RTF _rtf = new RTF())
|
||||||
|
{
|
||||||
// use nearest solid color
|
// use nearest solid color
|
||||||
// (the RTF control doesn't dither, and doesn't support transparent backgrounds)
|
// (the RTF control doesn't dither, and doesn't support transparent backgrounds)
|
||||||
Color solid = e.Graphics.GetNearestColor(e.Style.BackColor);
|
Color solid = e.Graphics.GetNearestColor(e.Style.BackColor);
|
||||||
@ -346,6 +347,7 @@ namespace Volian.Controls.Library
|
|||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
private void DrawCellBorder(Graphics graphics, Rectangle rectangle, int row, int col)
|
private void DrawCellBorder(Graphics graphics, Rectangle rectangle, int row, int col)
|
||||||
{
|
{
|
||||||
int x1 = rectangle.Left;
|
int x1 = rectangle.Left;
|
||||||
@ -1897,6 +1899,148 @@ namespace Volian.Controls.Library
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
//}
|
//}
|
||||||
|
#region Uneven Selections
|
||||||
|
/// <summary>
|
||||||
|
/// True if the top and bottom row of the selection is the same for every column
|
||||||
|
/// </summary>
|
||||||
|
public bool EvenSelection
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (Selection.c1 < 0 || Selection.c2 < 0 || Selection.r1 < 0 || Selection.r2 < 0) return true; // Even if there is no selection
|
||||||
|
if (Selection.IsSingleCell) return true; // One cell by definition is Even
|
||||||
|
int cMin = MinimumColumn(Selection.r1, Selection.c1); // Get the left column of the top row
|
||||||
|
int cMax = MaximumColumn(Selection.r1, Selection.c2); // Get the right column of the top row
|
||||||
|
for (int r = Selection.r1 + 1; r <= Selection.r2; r++)
|
||||||
|
{
|
||||||
|
// Uneven if the top row in this column doesn't match the first column
|
||||||
|
if (MinimumColumn(r, Selection.c1) != cMin)
|
||||||
|
return false;
|
||||||
|
// Uneven if the bottom row in this column doesn't match the first column
|
||||||
|
if (MaximumColumn(r, Selection.c2) != cMax)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
int rMin = MinimumRow(Selection.r1, Selection.c1); // Get the top row of the left column
|
||||||
|
int rMax = MaximumRow(Selection.r2, Selection.c1); // Get the bottom row of the left column
|
||||||
|
for (int c = Selection.c1 + 1; c <= Selection.c2; c++)
|
||||||
|
{
|
||||||
|
// Uneven if the top row in this column doesn't match the first column
|
||||||
|
if (MinimumRow(Selection.r1, c) != rMin)
|
||||||
|
return false;
|
||||||
|
// Uneven if the bottom row in this column doesn't match the first column
|
||||||
|
if (MaximumRow(Selection.r2, c) != rMax)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void MakeSelectionEven()
|
||||||
|
{
|
||||||
|
if (Selection.IsSingleCell) return; // One cell by definition is Even
|
||||||
|
MakeSelectionEven(Selection.r1, Selection.c1, Selection.r2, Selection.c2);
|
||||||
|
}
|
||||||
|
public void SelectRow()
|
||||||
|
{
|
||||||
|
MakeSelectionEven(Selection.r1, 0, Selection.r2, Cols.Count - 1);
|
||||||
|
}
|
||||||
|
public void SelectCol()
|
||||||
|
{
|
||||||
|
MakeSelectionEven(0, Selection.c1, Rows.Count - 1, Selection.c2);
|
||||||
|
}
|
||||||
|
public void MakeSelectionEven(int r1,int c1, int r2, int c2)
|
||||||
|
{
|
||||||
|
if (c1 < 0 || c2 < 0 || r1 < 0 || r2 < 0) return; // if there is no selection don't bother
|
||||||
|
int cMinNew = MinimumColumn(r1, c1); // Get the left column of the top row
|
||||||
|
int cMaxNew = MaximumColumn(r1, c2); // Get the right column of the top row
|
||||||
|
int rMinNew = MinimumRow(r1, c1); // Get the top row of the left column
|
||||||
|
int rMaxNew = MaximumRow(r2, c1); // Get the bottom row of the left column
|
||||||
|
int cMin = cMinNew;
|
||||||
|
int cMax = cMaxNew;
|
||||||
|
int rMin = rMinNew;
|
||||||
|
int rMax = rMaxNew;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
cMin = cMinNew;
|
||||||
|
cMax = cMaxNew;
|
||||||
|
rMin = rMinNew;
|
||||||
|
rMax = rMaxNew;
|
||||||
|
for (int r = rMin; r <= rMax; r++)
|
||||||
|
{
|
||||||
|
// Uneven if the top row in this column doesn't match the first column
|
||||||
|
int myMin = MinimumColumn(r, cMin);
|
||||||
|
if (myMin < cMinNew)
|
||||||
|
cMinNew = myMin;
|
||||||
|
// Uneven if the bottom row in this column doesn't match the first column
|
||||||
|
int myMax = MaximumColumn(r, cMax);
|
||||||
|
if (myMax > cMaxNew)
|
||||||
|
cMaxNew = myMax;
|
||||||
|
}
|
||||||
|
for (int c = cMinNew; c <= cMaxNew; c++)
|
||||||
|
{
|
||||||
|
// if the top row in this column is less than the minimum save it
|
||||||
|
int myMin = MinimumRow(rMin, c);
|
||||||
|
if (myMin < rMinNew)
|
||||||
|
rMinNew = myMin;
|
||||||
|
// Uneven if the bottom row in this column doesn't match the first column
|
||||||
|
int myMax = MaximumRow(rMax, c);
|
||||||
|
if (myMax > rMax)
|
||||||
|
rMaxNew = myMax;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (cMinNew < cMin || cMaxNew > cMax || rMinNew < rMin || rMaxNew > rMax);
|
||||||
|
Select(rMinNew, cMinNew, rMaxNew, cMaxNew);
|
||||||
|
}
|
||||||
|
private int MinimumColumn(int r, int c)
|
||||||
|
{
|
||||||
|
return GetMergedRange(r, c).c1;
|
||||||
|
}
|
||||||
|
private int MaximumColumn(int r, int c)
|
||||||
|
{
|
||||||
|
return GetMergedRange(r, c).c2;
|
||||||
|
}
|
||||||
|
private int MinimumRow(int r, int c)
|
||||||
|
{
|
||||||
|
return GetMergedRange(r, c).r1;
|
||||||
|
}
|
||||||
|
private int MaximumRow(int r, int c)
|
||||||
|
{
|
||||||
|
return GetMergedRange(r, c).r2;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a list of cells or merged cells within the selection
|
||||||
|
/// </summary>
|
||||||
|
public List<CellRange> MySelection
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
List<CellRange> ranges = new List<CellRange>();
|
||||||
|
for (int c = Selection.c1; c <= Selection.c2; c++)
|
||||||
|
for (int r = Selection.r1; r <= Selection.r2; r++)
|
||||||
|
{
|
||||||
|
CellRange cr = GetMergedRange(r, c);
|
||||||
|
if (!ranges.Contains(cr))
|
||||||
|
ranges.Add(cr);
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
return ranges;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// This is a test to see if MySelection works.
|
||||||
|
/// </summary>
|
||||||
|
public void BoldMySelection()
|
||||||
|
{
|
||||||
|
foreach (CellRange cr in MySelection)
|
||||||
|
{
|
||||||
|
StepRTB rtb = new StepRTB();
|
||||||
|
rtb.Rtf = GetCellRTFString(cr.r1, cr.c1);
|
||||||
|
rtb.SelectAll();
|
||||||
|
rtb.SelectionFont = new Font(rtb.SelectionFont, FontStyle.Bold);
|
||||||
|
this[cr.r1, cr.c1] = rtb.Rtf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
#region RTF Class for Cell rendering
|
#region RTF Class for Cell rendering
|
||||||
class RTF : StepRTB //RichTextBox
|
class RTF : StepRTB //RichTextBox
|
||||||
|
Loading…
x
Reference in New Issue
Block a user