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;
DrawItem += new DrawItemEventHandler(BorderListBox_DrawItem);
//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.Double));
Items.Add(new GridLBItem(GridLinePattern.Thick));
@ -42,13 +42,34 @@ namespace Volian.Controls.Library
Items.Add(new GridLBItem(GridLinePattern.Dotted));
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
#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);
}
return _MaxLabelWidth;
}
void BorderListBox_DrawItem(object sender, DrawItemEventArgs e)
private void BorderListBox_DrawItem(object sender, DrawItemEventArgs e)
{
e.DrawBackground();
e.DrawFocusRectangle();
@ -57,7 +78,7 @@ namespace Volian.Controls.Library
Brush myBrush = new SolidBrush(e.ForeColor);
e.Graphics.DrawString(myGridLBItem.LinePattern.ToString(), Font, myBrush, e.Bounds);
Pen pn = VlnBorders.LinePen(myGridLBItem.LinePattern, e.ForeColor);
int leftMargin = 50;
int leftMargin = MaxLabelWidth(e.Graphics);
int rightMargin = 4;
switch (myGridLBItem.LinePattern)
{

View File

@ -198,20 +198,29 @@ namespace Volian.Controls.Library
int w1 = Width - 2 * margin - 1;
int h1 = Height - 2 * margin - 1;
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);
}
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.DrawLine(Pens.LightBlue, x1, offset, x1, y1);
e.Graphics.DrawLine(Pens.LightBlue, x2, offset, x2, y1);
e.Graphics.DrawLine(Pens.LightBlue, x1, y2, x1, h2 - offset);
e.Graphics.DrawLine(Pens.LightBlue, x2, y2, x2, h2 - offset);
e.Graphics.DrawLine(Pens.LightBlue, offset, y1, x1, y1);
e.Graphics.DrawLine(Pens.LightBlue, x2, y1, w2 - offset, y1);
e.Graphics.DrawLine(Pens.LightBlue, offset, y2, x1, y2);
e.Graphics.DrawLine(Pens.LightBlue, x2, y2, w2 - offset, y2);
e.Graphics.FillRectangle(Brushes.White, offset, offset, w2 - 2* offset, h2 - 2* offset);
// Old Backgound - Shows corners
//e.Graphics.DrawLine(Pens.LightBlue, x1, offset, x1, y1);
//e.Graphics.DrawLine(Pens.LightBlue, x2, offset, x2, y1);
//e.Graphics.DrawLine(Pens.LightBlue, x1, y2, x1, h2 - offset);
//e.Graphics.DrawLine(Pens.LightBlue, x2, y2, x2, h2 - offset);
//e.Graphics.DrawLine(Pens.LightBlue, offset, y1, x1, y1);
//e.Graphics.DrawLine(Pens.LightBlue, x2, y1, w2 - offset, y1);
//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)
{

View File

@ -163,6 +163,8 @@ namespace Volian.Controls.Library
{
if (MyFlexGrid.Selection.c1 < 0 || MyFlexGrid.Selection.r1 < 0)
return;
if (MyFlexGrid.Selection.c1 >= MyFlexGrid.Cols.Count-1 || MyFlexGrid.Selection.r1 >= MyFlexGrid.Rows.Count-1)
return;
C1.Win.C1FlexGrid.CellRange cr = MyFlexGrid.GetEvenSelection();
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
_RibbonControl.AutoExpand = false;
_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)
@ -1891,26 +1895,25 @@ namespace Volian.Controls.Library
MyEditItem.Invalidate();
MyFlexGrid.Invalidate();
}
private void btnTblNoBorder_Click(object sender, EventArgs e)
{
rbnBorderSelectionPanel.AllBorders = GridLinePattern.None;
}
private void btnTblOutline_Click(object sender, EventArgs e)
{
rbnBorderSelectionPanel.OutlineBorder = rbnBorderlistBox.SelectedLinePattern;
}
private void btnTblInside_Click(object sender, EventArgs e)
{
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 class StepTabRibbonEventArgs : EventArgs
{

View File

@ -660,10 +660,10 @@ namespace Volian.Controls.Library
DisplayText dt = new DisplayText(gi.MyItemInfo, rtfText, true);
rtfText = dt.StartText;
}
// it does, so draw background
e.DrawCell(DrawCellFlags.Background);
if (rtfText.StartsWith(@"{\rtf"))
{
// it does, so draw background
e.DrawCell(DrawCellFlags.Background);
// draw the RTF text
if (e.Bounds.Width > 0 && e.Bounds.Height > 0)
@ -683,23 +683,23 @@ namespace Volian.Controls.Library
}
if (e.Style != null)
{
switch (e.Style.TextAlign)
{
case TextAlignEnum.CenterBottom:
case TextAlignEnum.GeneralBottom:
case TextAlignEnum.LeftBottom:
case TextAlignEnum.RightBottom:
hAdjust = hDiff;
break;
case TextAlignEnum.CenterCenter:
case TextAlignEnum.GeneralCenter:
case TextAlignEnum.LeftCenter:
case TextAlignEnum.RightCenter:
hAdjust = hDiff / 2;
break;
default:
break;
}
switch (e.Style.TextAlign)
{
case TextAlignEnum.CenterBottom:
case TextAlignEnum.GeneralBottom:
case TextAlignEnum.LeftBottom:
case TextAlignEnum.RightBottom:
hAdjust = hDiff;
break;
case TextAlignEnum.CenterCenter:
case TextAlignEnum.GeneralCenter:
case TextAlignEnum.LeftCenter:
case TextAlignEnum.RightCenter:
hAdjust = hDiff / 2;
break;
default:
break;
}
}
if (IsRoTable)
{
@ -710,19 +710,18 @@ namespace Volian.Controls.Library
_rtf.ForeColor = e.Style.ForeColor;
}
_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);
//Console.WriteLine("ownerDraw UserData [{0},{1}] = {2}", cr.r1, cr.c1, _rtf.ContentsRectangle.Height);
//cr.UserData = _rtf.ContentsRectangle.Height;
}
// and draw border last
//e.DrawCell(DrawCellFlags.Border);
// This can be used to draw more specific borders
DrawCellBorder(e);
// we're done with this cell
e.Handled = true;
}
// and draw border last
//e.DrawCell(DrawCellFlags.Border);
// This can be used to draw more specific borders
DrawCellBorder(e);
// we're done with this cell
e.Handled = true;
}
}
@ -3003,7 +3002,8 @@ namespace Volian.Controls.Library
TrimMergedRangeCellText(cr);
}
}
}
MyBorders = new VlnBorders(GridLinePattern.Single, Rows.Count, Cols.Count);
}
//private Regex _RemoveComments = new Regex(@"\\v .*?\\v0( |$)");