自定义标题栏右键菜单

摘自:http://stackoverflow.com/questions/4615940/how-can-i-customize-the-system-menu-of-a-windows-form

在单击窗体左上角图标,或标题栏右击时,显示自定义菜单

Imports System.Windows.Forms
Imports System.Runtime.InteropServices

Public Class CustomForm
    Inherits Form
    ‘ P/Invoke constants
    Private Const WM_SYSCOMMAND As Integer = &H112
    Private Const MF_STRING As Integer = &H0
    Private Const MF_SEPARATOR As Integer = &H800

    ‘ P/Invoke declarations
    <DllImport("user32.dll", CharSet:=CharSet.Auto, SetLastError:=True)>
    Private Shared Function GetSystemMenu(hWnd As IntPtr, bRevert As Boolean) As IntPtr
    End Function

    <DllImport("user32.dll", CharSet:=CharSet.Auto, SetLastError:=True)>
    Private Shared Function AppendMenu(hMenu As IntPtr, uFlags As Integer, uIDNewItem As Integer, lpNewItem As String) As Boolean
    End Function

    <DllImport("user32.dll", CharSet:=CharSet.Auto, SetLastError:=True)>
    Private Shared Function InsertMenu(hMenu As IntPtr, uPosition As Integer, uFlags As Integer, uIDNewItem As Integer, lpNewItem As String) As Boolean
    End Function

    ‘ ID for the About item on the system menu
    Private SYSMENU_ABOUT_ID As Integer = &H1

    Public Sub New()
    End Sub

    Protected Overrides Sub OnHandleCreated(e As EventArgs)
        MyBase.OnHandleCreated(e)

        ‘ Get a handle to a copy of this form‘s system (window) menu
        Dim hSysMenu As IntPtr = GetSystemMenu(Me.Handle, False)

        ‘ Add a separator
        AppendMenu(hSysMenu, MF_SEPARATOR, 0, String.Empty)

        ‘ Add the About menu item
        AppendMenu(hSysMenu, MF_STRING, SYSMENU_ABOUT_ID, "&About…")
    End Sub

    Protected Overrides Sub WndProc(ByRef m As Message)
        MyBase.WndProc(m)

        ‘ Test if the About item was selected from the system menu
        If m.Msg = WM_SYSCOMMAND AndAlso m.WParam.ToInt32 = SYSMENU_ABOUT_ID Then
            MessageBox.Show("Custom About Dialog")
        End If
    End Sub
End Class

  

时间: 2025-01-02 16:33:14

自定义标题栏右键菜单的相关文章

完美拖拽 &amp;&amp;仿腾讯微博效果&amp;&amp; 自定义多级右键菜单

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-

简单的自定义鼠标右键菜单

Window95 在PC中引入上下文菜单的概念,即通过鼠标右键调出上下文菜单,不久之后这个概念也被引入web中. 接下来我们来学习一下如何js自定义鼠标右键的菜单.  1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="UTF-8"> 5 <title>contextmenu</title> 6 </head> 7 <body> 8 //

创建自定义的右键菜单

1.当前的控件的Rect 2.当前事件是鼠标按下事件,并且是按下的鼠标右键 3.右键点击位置在Rect内 1 void MyContexMenu(Rect rect) 2 { 3 if(Event.current.type == EventType.MouseDown && 4 Event.current.button == 1 && 5 rect.Contains(Event.current.mousePosition)) 6 { 7 GenericMenu menu =

1:完成留言效果 2:完成拖动标题控制弹框拖拽 3 : 给弹框添加一个自定义的右键菜单

css部分 *{ margin: 0; padding: 0;}body,html{ width: 100%; height: 100%; position: relative;}li{ margin-top: 10px; list-style: none; border-bottom: 1px dashed #ccc;}#box{ width: 500px; border: 2px solid #ccc; padding: 30px;}#btn{ margin-top: 20px; margi

JavaScript特效——自定义鼠标右键菜单

HTML 1 .menu{ 2 position:absolute; 3 width:200px; 4 background:#eee; 5 border:1px solid #ddd; 6 box-shadow:2px 2px 2px 2px #999; 7 display: none; 8 } 9 ul{ 10 padding:0; 11 margin:0; 12 list-style-type:none; 13 } 14 ul li a{ 15 padding:5px 10px; 16 d

javascript 自定义鼠标右键菜单

<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> <style> #menu{ border:solid 1px gray; width:100px; display:none; position:absolute; background-color:ghostwhite; margin: 0; padding:

自定义右键菜单

自定义右键菜单 技术一般水平有限,有什么错的地方,望大家指正. 自定义右键菜单,对于一些ERP系统,功能操作比较多,所以我们通常把常用的几个功能放在自定义的右键菜单里方便用户使用. 实现自定义菜单很简单,首先我们要屏蔽原始的右键菜单,自定义菜单出现在鼠标的位置,点击隐藏自定义菜单,过程就是这样的. *{margin:0;padding:0} a{text-decoration:none} ul li{list-style:none} .menu{border:1px solid black;bo

自定义右键菜单,禁用浏览器自带的右键菜单[右键菜单实现--Demo]

许多从事Web开发的会发现有些事,我们需要禁用浏览器本事自带的右键菜单,而实现自定义的右键菜单下面我们也来实现一个自定义的右键菜单 首先来创建JSP页面 1 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> 2 <html> 3 <head> 4 <title>右键菜单</title> 5 <s

PyQt按钮右键菜单

本文原创,转载请注明原地址. 作者:酒醉东坡 原文地址:http://blog.csdn.net/jiuzuidongpo/article/details/46507403 实现效果如下图: 这篇文字主要写了两方面的内容: 第一是按钮的自定义,第二是右键菜单的使用,不仅是按钮的右键菜单,其他一些控件的右键菜单也可以类似创建和使用. 关于右键菜单则是QMenu的一些使用方法有: 样式表的使用: self.setStyleSheet("QMenu{background:purple;}"