Detecting a click on the caption bar.

Need to detect a click on the caption bar? You can easily intercept the required windows message (WM_NCLBUTTONDOWN).

Option Strict On
Option
 Explicit On

Imports
 System
Imports System.Windows.Forms
Imports System.Drawing

Public Class Form1
    
Inherits Form

    
Private ReadOnly WM_NCLBUTTONDOWN As Integer = &HA1

    
Public Sub New()
        
Me.Text = "Window Caption"
    End Sub

    Protected Overrides Sub WndProc(ByRef m As Message)
        
If m.msg = WM_NCLBUTTONDOWN Then
            Console.WriteLine("caption click...")
        
End if
        MyBase.WndProc(m)
    
End Sub

    <STAThread()> _
    
Shared Sub Main()
        Application.Run(
New Form1())
    
End Sub
End
 Class

2 Comments

  • hi





    this process fails does not work.





    recheck it





    devinder

  • Right now, the code is designed to be compiled as a console app -- not a windows app. If you compile it as a console app, there will be a console window where you'll see the &quot;caption click...&quot; message when the user clicks on the caption bar.





    Here's the command-line I used to compile:


    vbc /r:system.dll,system.windows.forms.dll,system.drawing.dll /t:exe captionclick.vb


Comments have been disabled for this content.