Ideas on how to display a modern message box as a hint

I need to display a non-modular message box whenever a user hovers over a menu item. I can not use messagebox.show (...) because it is modal. So what I did was create a separate window form and display the form using the hover event in the menu item. I have 2 problems:

1) When window forms are displayed, the menu loses its visibility.
2) The shape of the window does not appear next to the menu item, for example, as a tooltip.

Any ideas on how I could push a component tooltip that will make it look and act like a window shape?

+4
source share
2 answers

To answer your second problem:

If you set the form.StartPosition property to FormStartPosition.Manual , then you can put the form in the cursor (for example):

 form.StartPosition = FormStartPosition.Manual; form.Location = new Point(Cursor.Position.X - 1, Cursor.Position.Y - 1); 

This may help with your first problem.

If you want the form to behave like a tooltip, then if you add the following event handler code, this may give you a wish:

  private void Form_MouseLeave(object sender, EventArgs e) { // Only close if cursor actually outside the popup and not over a label if (Cursor.Position.X < Location.X || Cursor.Position.Y < Location.Y || Cursor.Position.X > Location.X + Width - 1 || Cursor.Position.Y > Location.Y + Height - 1) { Close(); } } 

This explains -1 when adjusting the position of the form. This ensures that the cursor is actually displayed in the form when it is first displayed.

+5
source

Since the Form class is just a wrapper around its own window, you can use the following snippet to create your own pop-up form that looks almost like a tooltip:

 public class PopupForm : Form { private const int SWP_NOSIZE = 0x0001; private const int SWP_NOMOVE = 0x0002; private const int SWP_NOACTIVATE = 0x0010; private const int WS_POPUP = unchecked((int)0x80000000); private const int WS_BORDER = 0x00800000; private const int WS_EX_TOPMOST = 0x00000008; private const int WS_EX_NOACTIVATE = 0x08000000; private const int CS_DROPSHADOW = 0x00020000; private static readonly IntPtr HWND_TOPMOST = (IntPtr)(-1); [DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags); public PopupForm() { InitializeComponent(); SetStyle(ControlStyles.Selectable, false); Visible = false; } protected virtual void InitializeComponent() { FormBorderStyle = FormBorderStyle.None; StartPosition = FormStartPosition.Manual; ShowInTaskbar = false; BackColor = SystemColors.Info; // ... } protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; cp.Style |= WS_POPUP; cp.Style |= WS_BORDER; cp.ExStyle |= WS_EX_TOPMOST | WS_EX_NOACTIVATE; //if (Microsoft.OS.IsWinXP && SystemInformation.IsDropShadowEnabled) // cp.ClassStyle |= CS_DROPSHADOW; return cp; } } protected override bool ShowWithoutActivation { get { return true; } } public new void Show() { SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOMOVE); base.Show(); } public void Show(Point p) { Location = p; Show(); } } 

Manage this form using the Show () and Hide () methods from external code.

+5
source

Source: https://habr.com/ru/post/1286462/


All Articles