/// <summary> /// Show a "tip of the day"-like message on the top right corner of the given window. /// </summary> /// <param name="form">The owner window.</param> /// <param name="key">The key used to store informations about messages the user already saw. Every messages is only displayed once.</param> /// <param name="title">The title of the tip window.</param> /// <param name="tiptext">The text of the tip window.</param> /// <param name="checkBoxVisible">if set to <c>true</c> the checkbox is visible.</param> /// <exception cref="System.ArgumentNullException">form</exception> public static void ShowTip(Form form, string key, string title, string tiptext, bool checkBoxVisible = true) { form.ThrowIfNull(nameof(form)); if (Settings.UI.ConfirmedTips.Contains(key)) return; // Quit if it's already shown if (form.Controls.OfType<TipWindow>().Any()) return; // Gets disposed when clicking the OK button TipWindow tipWindow = new TipWindow(form, title, tiptext, key, checkBoxVisible); tipWindow.Show(); }
/// <summary> /// Sets the tool tip location. /// </summary> /// <param name="tooltipForm">The tooltip form.</param> /// <exception cref="System.ArgumentNullException">tooltipForm</exception> public static void SetToolTipLocation(Form tooltipForm) { tooltipForm.ThrowIfNull(nameof(tooltipForm)); Point mp = Control.MousePosition; NativeMethods.AppBarData appBarData = NativeMethods.AppBarData.Create(); NativeMethods.SHAppBarMessage(NativeMethods.ABM_GETTASKBARPOS, ref appBarData); NativeMethods.RECT taskBarLocation = appBarData.Rect; Screen curScreen = Screen.FromPoint(mp); Point winPoint; bool slideLeftRight; switch (appBarData.UEdge) { default: winPoint = mp; slideLeftRight = true; break; case NativeMethods.ABE_BOTTOM: winPoint = new Point(mp.X, taskBarLocation.Top - tooltipForm.Height); slideLeftRight = true; break; case NativeMethods.ABE_TOP: winPoint = new Point(mp.X, taskBarLocation.Bottom); slideLeftRight = true; break; case NativeMethods.ABE_LEFT: winPoint = new Point(taskBarLocation.Right, mp.Y); slideLeftRight = false; break; case NativeMethods.ABE_RIGHT: winPoint = new Point(taskBarLocation.Left - tooltipForm.Width, mp.Y); slideLeftRight = false; break; } if (slideLeftRight) { if (winPoint.X + tooltipForm.Width > curScreen.Bounds.Right) winPoint = new Point(curScreen.Bounds.Right - tooltipForm.Width - 1, winPoint.Y); if (winPoint.X < curScreen.Bounds.Left) winPoint = new Point(curScreen.Bounds.Left + 2, winPoint.Y); } else { if (winPoint.Y + tooltipForm.Height > curScreen.Bounds.Bottom) winPoint = new Point(winPoint.X, curScreen.Bounds.Bottom - tooltipForm.Height - 1); if (winPoint.Y < curScreen.Bounds.Top) winPoint = new Point(winPoint.X, curScreen.Bounds.Top + 2); } tooltipForm.Location = winPoint; }