Search code examples
vb.netwinformstitlebar

How can I place a button on the title bar?


I am attempting to make a button that shows a user-menu, as seen in Google Chrome:

enter image description here

There's no legacy way of doing this, so I've had a look around and I have found that every way of doing this is either outdated or does not work (probably because it's outdated!).

This is the first link I found, but however it only works with Windows Aero off, and probably not with Windows 8, 8.1, or 10, and not very well. The answer to this Stack Overflow question is also essentially the same code:

enter image description here

Aero on:

enter image description here

I have also found some questions here, but the techniques mentioned do not work. One of the answers points to this MSDN article which appears to offer some of the functionality I want, but the code however is .

Is this possible in VB.NET without any issues, and if so, how?

This is with VB.NET and Windows Forms, target operating systems are Windows 7 and newer.


Solution

  • Take a look at these 2 links:

    Adding caption buttons to the Non-client area on Vista

    .Net ActiveButtons Library

    It's been a while since I've used VB.Net, so if you don't mind I'll just add a c# code example (basically I took the example from the first link and tried it, it seems to be working fine)

    private void Form1_Load(object sender, EventArgs e)
    {
        IActiveMenu menu = ActiveMenu.GetInstance(this);
        ActiveButton button = new ActiveButton();
        button.BackColor = Color.LightBlue;
        button.Text = "One";
        button.Click += button_Click;
        menu.Items.Add(button);
    }
    
    private void button_Click(object sender, EventArgs e)
    {
        MessageBox.Show("Button clicked");
    }
    

    Note: This button doesn't seem to support transparent background, so it doesn't look quite as good as the button in chrome.