RichTextBox pseudo caret when it doesn't have focus
This commit is contained in:
@@ -33,6 +33,7 @@ namespace Volian.Controls.Library
|
||||
private int _UniqueBarCount;
|
||||
private ItemInfo _MyItemInfo = null;
|
||||
private EditItem _MyEditItem = null;
|
||||
private StepRTB _MyStepRTB = null;
|
||||
private bool _RibbonExpanded=true;
|
||||
public bool RibbonExpanded
|
||||
{
|
||||
@@ -155,11 +156,16 @@ namespace Volian.Controls.Library
|
||||
{
|
||||
_MyItemInfo = args.MyItemInfo;
|
||||
_MyEditItem = args.MyEditItem;
|
||||
if (_MyEditItem != null)
|
||||
_MyStepRTB = _MyEditItem.MyStepRTB;
|
||||
else
|
||||
_MyStepRTB = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
_MyItemInfo = null;
|
||||
_MyEditItem = null;
|
||||
_MyStepRTB = null;
|
||||
}
|
||||
if (ItemSelectedChanged != null) ItemSelectedChanged(sender, args);
|
||||
}
|
||||
@@ -471,6 +477,54 @@ namespace Volian.Controls.Library
|
||||
{
|
||||
get { return _MyBar; }
|
||||
}
|
||||
public Panel PnlCaret
|
||||
{
|
||||
get { return _PnlCaret; }
|
||||
}
|
||||
public void ShowCaret()
|
||||
{
|
||||
if (_MyStepRTB != null)
|
||||
{
|
||||
if (!_MyStepRTB.Visible)
|
||||
_MyStepRTB.Visible = true;
|
||||
if (_MyStepRTB.SelectionLength == 0)
|
||||
{
|
||||
Point pt = _MyStepRTB.GetPositionFromCharIndex(_MyStepRTB.SelectionStart);
|
||||
pt = _MyStepRTB.PointToScreen(pt);
|
||||
pt = this.PointToClient(pt);
|
||||
PnlCaret.Location = pt;
|
||||
PnlCaret.BackColor = _MyStepRTB.ForeColor;
|
||||
using (Graphics gr = this.CreateGraphics())
|
||||
{
|
||||
SizeF sf = gr.MeasureString("Mg", _MyStepRTB.SelectionFont);
|
||||
sf.Width = 1;
|
||||
PnlCaret.Size = sf.ToSize();
|
||||
}
|
||||
tmrCaret.Enabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
_MyStepRTB.SelectionColor = Color.White;
|
||||
_MyStepRTB.SelectionBackColor = Color.FromName("Highlight");
|
||||
}
|
||||
}
|
||||
}
|
||||
public void HideCaret()
|
||||
{
|
||||
if (_MyStepRTB != null && ! _MyStepRTB.Disposing)
|
||||
{
|
||||
if (_MyStepRTB.SelectionLength == 0)
|
||||
{
|
||||
tmrCaret.Enabled = false;
|
||||
PnlCaret.Visible = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
_MyStepRTB.SelectionColor = _MyStepRTB.ForeColor;
|
||||
_MyStepRTB.SelectionBackColor = _MyStepRTB.BackColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region Private Methods
|
||||
///// <summary>
|
||||
@@ -686,5 +740,9 @@ namespace Volian.Controls.Library
|
||||
myDisplayTabItem.Dispose();
|
||||
}
|
||||
#endregion
|
||||
private void tmrCaret_Tick(object sender, EventArgs e)
|
||||
{
|
||||
PnlCaret.Visible = !PnlCaret.Visible;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user