Commit 65876eb1 authored by JoyJ's avatar JoyJ

show label tooltip on autocomplete menu; use TextChanged, not Delay; adjust...

show label tooltip on autocomplete menu; use TextChanged, not Delay; adjust autocomplete menu automatically
parent c3d37479
......@@ -45,6 +45,7 @@ public CodeEditForm()
{
this.InitForm();
}
void InitForm()
{
this.cardlist = new SortedDictionary<long, string>();
......@@ -83,17 +84,55 @@ void InitForm()
MinFragmentLength = 2
};
this.popupMenu.Items.Font = ft;
this.popupMenu.Items.MaximumSize = new System.Drawing.Size(200, 400);
this.popupMenu.Items.Width = 300;
this.popupMenu.AutoSize = true;
this.popupMenu.MinimumSize = new System.Drawing.Size(300, 0);
this.popupMenu.BackColor = this.fctb.BackColor;
this.popupMenu.ForeColor = this.fctb.ForeColor;
this.popupMenu.Closed += new ToolStripDropDownClosedEventHandler(this.popupMenu_Closed);
this.popupMenu.SelectedColor = Color.LightGray;
popupMenu.VisibleChanged += this.PopupMenu_VisibleChanged;
popupMenu.Items.FocussedItemIndexChanged += this.Items_FocussedItemIndexChanged;
this.title = this.Text;
}
private void PopupMenu_VisibleChanged(object sender, EventArgs e)
{
this.AdjustPopupMenuSize();
if (!popupMenu.Visible || popupMenu.Items.FocussedItem == null)
{
return;
}
this.fctb.ShowTooltipWithLabel(popupMenu.Items.FocussedItem.ToolTipTitle,
popupMenu.Items.FocussedItem.ToolTipText);
}
private void AdjustPopupMenuSize()
{
if (!popupMenu.Visible || popupMenu.Items.FocussedItem == null)
{
popupMenu.Size = new Size(300, 0);
popupMenu.MinimumSize = new Size(300, 0);
}
Size s = TextRenderer.MeasureText(popupMenu.Items.FocussedItem.ToolTipTitle,
popupMenu.Items.Font, new Size(0, 0), TextFormatFlags.NoPadding);
s = new Size(s.Width + 50, popupMenu.Size.Height);
if (popupMenu.Size.Width < s.Width)
{
popupMenu.Size = s;
popupMenu.MinimumSize = s;
}
}
private void Items_FocussedItemIndexChanged(object sender, EventArgs e)
{
if (popupMenu.Items.FocussedItem == null)
{
return;
}
this.AdjustPopupMenuSize();
this.fctb.ShowTooltipWithLabel(popupMenu.Items.FocussedItem.ToolTipTitle,
popupMenu.Items.FocussedItem.ToolTipText);
}
void popupMenu_Closed(object sender, ToolStripDropDownClosedEventArgs e)
{
this.popupMenu.Items.SetAutocompleteItems(this.items);
......
......@@ -16,17 +16,20 @@ namespace FastColoredTextBoxNS
{
public class FastColoredTextBoxEx : FastColoredTextBox
{
private Label lbTooltip;
public Label lbTooltip;
Point lastMouseCoord;
public FastColoredTextBoxEx() : base()
{
this.SyntaxHighlighter = new MySyntaxHighlighter();
this.InitializeComponent();
this.TextChanged += this.FctbTextChanged;
this.ToolTipDelay = 1;
this.TextChangedDelayed += this.FctbTextChangedDelayed;
}
public new event EventHandler<ToolTipNeededEventArgs> ToolTipNeeded;
this.DelayedEventsInterval = 1;
this.DelayedTextChangedInterval = 1;
this.InitializeComponent();
}
public new event EventHandler<ToolTipNeededEventArgs> ToolTipNeeded;
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
......@@ -64,19 +67,24 @@ protected override void OnToolTip()
if (ea.ToolTipText != null)
{
lbTooltip.Visible = true;
lbTooltip.Text = $"{ea.ToolTipTitle}\r\n\r\n{ea.ToolTipText}";
lbTooltip.Location = new Point(this.Size.Width - 500, this.lastMouseCoord.Y + this.CharHeight);
//this.ToolTip.ToolTipTitle = ea.ToolTipTitle;
//this.ToolTip.ToolTipIcon = ea.ToolTipIcon;
//ToolTip.SetToolTip(this, ea.ToolTipText);
//this.ToolTip.Show(ea.ToolTipText, this, new Point(this.lastMouseCoord.X, this.lastMouseCoord.Y + this.CharHeight));
this.ShowTooltipWithLabel(ea.ToolTipTitle, ea.ToolTipText);
}
}
public void ShowTooltipWithLabel(string title, string text, int height)
{
lbTooltip.Visible = true;
lbTooltip.Text = $"{title}\r\n\r\n{text}";
lbTooltip.Location = new Point(this.Size.Width - 500, height);
}
public void ShowTooltipWithLabel(string title, string text)
{
this.ShowTooltipWithLabel(title,text, this.lastMouseCoord.Y + this.CharHeight);
}
//高亮当前词
void FctbTextChangedDelayed(object sender, TextChangedEventArgs e)
void FctbTextChanged(object sender, TextChangedEventArgs e)
{
//delete all markers
this.Range.ClearFoldingMarkers();
......
......@@ -112,9 +112,9 @@
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment