Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows Forms
  4. How to detect mouse over & out on win form title bar

How to detect mouse over & out on win form title bar

Scheduled Pinned Locked Moved Windows Forms
csharphelptutorial
1 Posts 1 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tridip Bhattacharjee
    wrote on last edited by
    #1

    i want to detect mouse over on title bar or mouse out from title bar in my c# winform apps. i got a code sample which works but the problem is when i place the mouse on any area of win form then mouse leave occur and when i put mouse on title bar then right event call. actually i want that if i place my mouse on any area of form except title bar then nothing should happen.only when i will place mouse on title bar then a notification should come to me and when i will remove mouse from title to out of my form then label should display mouse out message but if remove mouse from title bar to form body then label should be blank. here is code. just run this code and tell me what modification i should do to get my expected result. thanks using System.Runtime.InteropServices; public partial class Form2 : Form { public Form2() { InitializeComponent(); } protected override void WndProc(ref Message m) { if (m.Msg == 0xA0) // WM_NCMOUSEMOVE { TrackNcMouseLeave(this); //ShowClientArea(); label1.Text = "mouse move on title bar"; } else if (m.Msg == 0x2A2) // WM_NCMOUSELEAVE { //HideClientAreaIfPointerIsOut(); label1.Text = "mouse leave from title bar"; } base.WndProc(ref m); } protected override void OnMouseLeave(EventArgs e) { base.OnMouseLeave(e); //HideClientAreaIfPointerIsOut(); } private int previouseHeight; private void ShowClientArea() { if (this.ClientSize.Height == 0) this.ClientSize = new Size(this.ClientSize.Width, previouseHeight); } private void HideClientAreaIfPointerIsOut() { if (this.Bounds.Contains(Cursor.Position)) return; previouseHeight = this.ClientSize.Height; this.ClientSize = new Size(this.ClientSize.Width, 0); } public static void TrackNcMouseLeave(Control control) { TRACKMOUSEEVENT tme = new TRACKMOUSEEVENT(); tme.cbSize = (uint)Marshal.SizeOf(tme); tme.dwFlags = 2 | 0x10; // TME_LEAVE | TME_NONCLIENT tme.hwndTrack = control.Handle; TrackMouseEvent(tme); } [DllImport("user32")] public static extern bool TrackMouseEvent([I

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups