Initialize BorderListBox based upon current DPI

Changed background for border selection
Draw Background and Borders for empty cells
Set the Borders druing Grid conversion
This commit is contained in:
Rich 2011-03-21 16:33:29 +00:00
parent f36d16d84c
commit ec9932d93e
4 changed files with 84 additions and 51 deletions

View File

@ -34,7 +34,7 @@ namespace Volian.Controls.Library
//this.Font.Size; //this.Font.Size;
DrawItem += new DrawItemEventHandler(BorderListBox_DrawItem); DrawItem += new DrawItemEventHandler(BorderListBox_DrawItem);
//MeasureItem += new MeasureItemEventHandler(BorderListBox_MeasureItem); //MeasureItem += new MeasureItemEventHandler(BorderListBox_MeasureItem);
Items.Add(new GridLBItem( GridLinePattern.None )); Items.Add(new GridLBItem(GridLinePattern.None));
Items.Add(new GridLBItem(GridLinePattern.Single)); Items.Add(new GridLBItem(GridLinePattern.Single));
Items.Add(new GridLBItem(GridLinePattern.Double)); Items.Add(new GridLBItem(GridLinePattern.Double));
Items.Add(new GridLBItem(GridLinePattern.Thick)); Items.Add(new GridLBItem(GridLinePattern.Thick));
@ -42,13 +42,34 @@ namespace Volian.Controls.Library
Items.Add(new GridLBItem(GridLinePattern.Dotted)); Items.Add(new GridLBItem(GridLinePattern.Dotted));
SelectedIndex = 1; SelectedIndex = 1;
} }
public void SetupFontAndSize(int fontSize)
{
Font = new Font(Font.FontFamily, fontSize, Font.Style);
using (Graphics gr = CreateGraphics())
{
SizeF mySize = gr.MeasureString("Almg", Font);
ItemHeight = (int)Math.Ceiling(mySize.Height);
}
int newHeight = Items.Count * ItemHeight + 4;
Size = new Size(newHeight, newHeight);
}
#endregion #endregion
#region Event Handlers #region Event Handlers
void BorderListBox_MeasureItem(object sender, MeasureItemEventArgs e) //void BorderListBox_MeasureItem(object sender, MeasureItemEventArgs e)
//{
// e.ItemHeight = 22;
//}
private int _MaxLabelWidth = 0;
private int MaxLabelWidth(Graphics gr)
{ {
e.ItemHeight = 22; if(_MaxLabelWidth == 0)
{
for(int i=0;i<Items.Count;i++)
_MaxLabelWidth = Math.Max(_MaxLabelWidth,(int) gr.MeasureString("XX" + Items[0].ToString(), Font).Width);
} }
void BorderListBox_DrawItem(object sender, DrawItemEventArgs e) return _MaxLabelWidth;
}
private void BorderListBox_DrawItem(object sender, DrawItemEventArgs e)
{ {
e.DrawBackground(); e.DrawBackground();
e.DrawFocusRectangle(); e.DrawFocusRectangle();
@ -57,7 +78,7 @@ namespace Volian.Controls.Library
Brush myBrush = new SolidBrush(e.ForeColor); Brush myBrush = new SolidBrush(e.ForeColor);
e.Graphics.DrawString(myGridLBItem.LinePattern.ToString(), Font, myBrush, e.Bounds); e.Graphics.DrawString(myGridLBItem.LinePattern.ToString(), Font, myBrush, e.Bounds);
Pen pn = VlnBorders.LinePen(myGridLBItem.LinePattern, e.ForeColor); Pen pn = VlnBorders.LinePen(myGridLBItem.LinePattern, e.ForeColor);
int leftMargin = 50; int leftMargin = MaxLabelWidth(e.Graphics);
int rightMargin = 4; int rightMargin = 4;
switch (myGridLBItem.LinePattern) switch (myGridLBItem.LinePattern)
{ {

View File

@ -198,20 +198,29 @@ namespace Volian.Controls.Library
int w1 = Width - 2 * margin - 1; int w1 = Width - 2 * margin - 1;
int h1 = Height - 2 * margin - 1; int h1 = Height - 2 * margin - 1;
int offset = 4; int offset = 4;
DrawBackground(e, x1, y1, x2, y2, w1, h1, w2, h2, offset); DrawBackground(e, x1, y1, x2, y2, w1, h1, w2, h2, offset, HasRows, HasColumns);
DrawBorder(e, x1, y1, x2, y2); DrawBorder(e, x1, y1, x2, y2);
} }
private static void DrawBackground(PaintEventArgs e, int x1, int y1, int x2, int y2, int w1, int h1, int w2, int h2, int offset) private static void DrawBackground(PaintEventArgs e, int x1, int y1, int x2, int y2, int w1, int h1, int w2, int h2, int offset,bool hasRows, bool hasColumns)
{ {
e.Graphics.FillRectangle(Brushes.White, x1, y1, w1, h1); e.Graphics.FillRectangle(Brushes.White, offset, offset, w2 - 2* offset, h2 - 2* offset);
e.Graphics.DrawLine(Pens.LightBlue, x1, offset, x1, y1); // Old Backgound - Shows corners
e.Graphics.DrawLine(Pens.LightBlue, x2, offset, x2, y1); //e.Graphics.DrawLine(Pens.LightBlue, x1, offset, x1, y1);
e.Graphics.DrawLine(Pens.LightBlue, x1, y2, x1, h2 - offset); //e.Graphics.DrawLine(Pens.LightBlue, x2, offset, x2, y1);
e.Graphics.DrawLine(Pens.LightBlue, x2, y2, x2, h2 - offset); //e.Graphics.DrawLine(Pens.LightBlue, x1, y2, x1, h2 - offset);
e.Graphics.DrawLine(Pens.LightBlue, offset, y1, x1, y1); //e.Graphics.DrawLine(Pens.LightBlue, x2, y2, x2, h2 - offset);
e.Graphics.DrawLine(Pens.LightBlue, x2, y1, w2 - offset, y1); //e.Graphics.DrawLine(Pens.LightBlue, offset, y1, x1, y1);
e.Graphics.DrawLine(Pens.LightBlue, offset, y2, x1, y2); //e.Graphics.DrawLine(Pens.LightBlue, x2, y1, w2 - offset, y1);
e.Graphics.DrawLine(Pens.LightBlue, x2, y2, w2 - offset, y2); //e.Graphics.DrawLine(Pens.LightBlue, offset, y2, x1, y2);
//e.Graphics.DrawLine(Pens.LightBlue, x2, y2, w2 - offset, y2);
// Horizontal Lines
e.Graphics.DrawLine(Pens.LightBlue, offset, y1, w2 - offset, y1);
if (hasRows) e.Graphics.DrawLine(Pens.LightBlue, x1 + offset, (y1 + y2) / 2, x2 - offset , (y1 + y2) / 2);
e.Graphics.DrawLine(Pens.LightBlue, offset, y2, w2 - offset, y2);
// Vertical Lines
e.Graphics.DrawLine(Pens.LightBlue, x1, offset, x1, h2 - offset);
if (hasColumns) e.Graphics.DrawLine(Pens.LightBlue, (x1 + x2) / 2, y1+offset, (x1 + x2) / 2, y2 - offset);
e.Graphics.DrawLine(Pens.LightBlue, x2, offset, x2, h2 - offset);
} }
private void DrawBorder(PaintEventArgs e, int x1, int y1, int x2, int y2) private void DrawBorder(PaintEventArgs e, int x1, int y1, int x2, int y2)
{ {

View File

@ -163,6 +163,8 @@ namespace Volian.Controls.Library
{ {
if (MyFlexGrid.Selection.c1 < 0 || MyFlexGrid.Selection.r1 < 0) if (MyFlexGrid.Selection.c1 < 0 || MyFlexGrid.Selection.r1 < 0)
return; return;
if (MyFlexGrid.Selection.c1 >= MyFlexGrid.Cols.Count-1 || MyFlexGrid.Selection.r1 >= MyFlexGrid.Rows.Count-1)
return;
C1.Win.C1FlexGrid.CellRange cr = MyFlexGrid.GetEvenSelection(); C1.Win.C1FlexGrid.CellRange cr = MyFlexGrid.GetEvenSelection();
rbnBorderSelectionPanel.InitializeBorder(MyFlexGrid.MyBorders, cr.r1, cr.c1, cr.r2, cr.c2); rbnBorderSelectionPanel.InitializeBorder(MyFlexGrid.MyBorders, cr.r1, cr.c1, cr.r2, cr.c2);
} }
@ -288,6 +290,8 @@ namespace Volian.Controls.Library
// Note: the QAT menu is to the right of the V start button in the upper left // Note: the QAT menu is to the right of the V start button in the upper left
_RibbonControl.AutoExpand = false; _RibbonControl.AutoExpand = false;
_RibbonControl.Items[0].RaiseClick(); // initially default to HOME tab _RibbonControl.Items[0].RaiseClick(); // initially default to HOME tab
rbnBorderlistBox.Resize+=new EventHandler(rbnBorderlistBox_Resize);
rbnBorderlistBox.SetupFontAndSize(6); // 6 Point Font
} }
void _RibbonControl_SizeChanged(object sender, EventArgs e) void _RibbonControl_SizeChanged(object sender, EventArgs e)
@ -1891,26 +1895,25 @@ namespace Volian.Controls.Library
MyEditItem.Invalidate(); MyEditItem.Invalidate();
MyFlexGrid.Invalidate(); MyFlexGrid.Invalidate();
} }
private void btnTblNoBorder_Click(object sender, EventArgs e) private void btnTblNoBorder_Click(object sender, EventArgs e)
{ {
rbnBorderSelectionPanel.AllBorders = GridLinePattern.None; rbnBorderSelectionPanel.AllBorders = GridLinePattern.None;
} }
private void btnTblOutline_Click(object sender, EventArgs e) private void btnTblOutline_Click(object sender, EventArgs e)
{ {
rbnBorderSelectionPanel.OutlineBorder = rbnBorderlistBox.SelectedLinePattern; rbnBorderSelectionPanel.OutlineBorder = rbnBorderlistBox.SelectedLinePattern;
} }
private void btnTblInside_Click(object sender, EventArgs e) private void btnTblInside_Click(object sender, EventArgs e)
{ {
rbnBorderSelectionPanel.InsideBorders = rbnBorderlistBox.SelectedLinePattern; rbnBorderSelectionPanel.InsideBorders = rbnBorderlistBox.SelectedLinePattern;
} }
private void rbnBorderlistBox_Resize(object sender, EventArgs e)
{
rbnBorderSelectionPanel.Size = rbnBorderlistBox.Size;
_RibbonControl.Height = rbnBorderlistBox.Height + _RibbonControl.Height - _RibbonControl.ClientSize.Height;
//_RibbonControl.Height = rbnBorderlistBox.Height + _RibbonControl.Height - _RibbonControl.ClientSize.Height;
}
} }
public enum E_FieldToEdit { StepText, Text, Number }; public enum E_FieldToEdit { StepText, Text, Number };
public class StepTabRibbonEventArgs : EventArgs public class StepTabRibbonEventArgs : EventArgs
{ {

View File

@ -660,10 +660,10 @@ namespace Volian.Controls.Library
DisplayText dt = new DisplayText(gi.MyItemInfo, rtfText, true); DisplayText dt = new DisplayText(gi.MyItemInfo, rtfText, true);
rtfText = dt.StartText; rtfText = dt.StartText;
} }
if (rtfText.StartsWith(@"{\rtf"))
{
// it does, so draw background // it does, so draw background
e.DrawCell(DrawCellFlags.Background); e.DrawCell(DrawCellFlags.Background);
if (rtfText.StartsWith(@"{\rtf"))
{
// 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)
@ -710,12 +710,12 @@ namespace Volian.Controls.Library
_rtf.ForeColor = e.Style.ForeColor; _rtf.ForeColor = e.Style.ForeColor;
} }
_rtf.BackColor = e.Style.BackColor; _rtf.BackColor = e.Style.BackColor;
_rtf.Render(e.Graphics, new Rectangle(e.Bounds.X+1,e.Bounds.Y + hAdjust,e.Bounds.Width-3,e.Bounds.Height)); _rtf.Render(e.Graphics, new Rectangle(e.Bounds.X + 1, e.Bounds.Y + hAdjust, e.Bounds.Width - 3, e.Bounds.Height));
//CellRange cr = GetCellRange(e.Row, e.Col); //CellRange cr = GetCellRange(e.Row, e.Col);
//Console.WriteLine("ownerDraw UserData [{0},{1}] = {2}", cr.r1, cr.c1, _rtf.ContentsRectangle.Height); //Console.WriteLine("ownerDraw UserData [{0},{1}] = {2}", cr.r1, cr.c1, _rtf.ContentsRectangle.Height);
//cr.UserData = _rtf.ContentsRectangle.Height; //cr.UserData = _rtf.ContentsRectangle.Height;
} }
}
// 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
@ -724,7 +724,6 @@ namespace Volian.Controls.Library
e.Handled = true; e.Handled = true;
} }
} }
}
private void DrawCellBorder(C1.Win.C1FlexGrid.OwnerDrawCellEventArgs e) private void DrawCellBorder(C1.Win.C1FlexGrid.OwnerDrawCellEventArgs e)
{ {
@ -3003,6 +3002,7 @@ namespace Volian.Controls.Library
TrimMergedRangeCellText(cr); TrimMergedRangeCellText(cr);
} }
} }
MyBorders = new VlnBorders(GridLinePattern.Single, Rows.Count, Cols.Count);
} }
//private Regex _RemoveComments = new Regex(@"\\v .*?\\v0( |$)"); //private Regex _RemoveComments = new Regex(@"\\v .*?\\v0( |$)");