VS 2015 Add button to the titlebar??-VBForums
Results 1 to 10 of 10

Thread: Add button to the titlebar??

  1. #1

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,200

    Add button to the titlebar??

    Ok ... Now I have seen many examples of how to do this... but all of them seem to be somewhat "tacked on" to me.

    Opera has a nice implementation of this as can be seen below:
    Name:  Opera.png
Views: 183
Size:  1.7 KB
    ... and works well with OS themes too ... and highlights correctly with the fading animation etc.

    But I have not really seen anything else that comes close to this in programming ...

    Even with rendering on the NC area... I still have the issue of how to "theme" the button ... as the built in renderer seems to use a "legacy" renderer (the one that is still used on MDI forms)...
    as can be seen below:
    VB.Net Code:
    1. Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
    2.     Dim r As New VisualStyles.VisualStyleRenderer(VisualStyles.VisualStyleElement.Window.HelpButton.Normal)
    3.     r.DrawBackground(e.Graphics, New Rectangle(0, 0, 32, 32))
    4. End Sub
    Name:  CrudRender.png
Views: 186
Size:  1.9 KB

    ...Any ideas or good examples on how to make this appear nice and be *somewhat* compatible?

    Thanks in advance,
    Kris

  2. #2
    Fanatic Member jdc20181's Avatar
    Join Date
    Oct 2015
    Location
    Indiana
    Posts
    1,009

    Re: Add button to the titlebar??

    One way to do it is make your button(s) Transparent, it would blend in whatever the themed color is. - If you are using the "Form.helpbutton" property, the button generated seems to be automatically configured with the white bar color , when I used the code: https://msdn.microsoft.com/en-us/lib...or=-2147217396

    Heres an Example of successfully getting the button to go transparent:


    Code:
     Button1.FlatStyle = FlatStyle.Flat
            Button1.FlatAppearance.BorderSize = 0
            Button1.FlatAppearance.MouseDownBackColor = Color.Transparent
            Button1.FlatAppearance.MouseOverBackColor = Color.Transparent
            Button1.BackColor = Color.Transparent
    Disclaimer: When code is given for example - it is merely a example. See my First CodeBank Submission Upgrading to the newest IE when using the Webbrowser control See my Second CodeBank SubmissionVB.NET - Recording History or changes using WebbrowserControl RichTextBox Textbox
    See my Third codebank submission VB.NET - Detecting Secure/Insecure Websites (ssl) w/ Webbrowser control See CodeBank Submission 4 A Simple Large View Calendar Control See my browser project BeffsBrowser Try my SpeedTest Project

    Unless said otherwise (e.g. From one of my projects thus, those are mostly licensed under MIT) - All Code snippets advice or otherwise that I post on this site, are expressly licensed under Creative Commons Attribution 4.0 International Please respect my copyrights.

  3. #3
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,025

    Re: Add button to the titlebar??

    This has always been kind of a pain point in Windows Forms. Most of the work to make matching the visual style "easy" came in WPF, which was largely ignored by application developers.

    Rendering Controls with Visual Styles seems to be a good resource for client area controls, but I don't see much that makes me believe it will do the right thing for non-client area controls. I can't find any documentation that seems to apply to non-client rendering while respecting the visual theme.

    I do know that long ago I noticed Chrome used the Vista-style title bar even on Windows XP, so I got curious and looked at the Chromium source to find out how. It turns out the answer is "Chromium is a borderless form. If visual styles are enabled, then rather than using the normal title bar, it draws its own title bar and borders so it can look consistent across all versions of Windows." That was years ago and might have changed since then. Opera may or may not be doing the same thing.

    I'm not sure jdc's suggestion will work as-is. "Transparent" in WinForms often means "the background color of the Form". In the NC context, I'm not sure what it means.
    Nothing I post is production-ready. It is provided as-is, use it at your own risk.

  4. #4

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,200

    Re: Add button to the titlebar??

    Quote Originally Posted by jdc20181 View Post
    One way to do it is make your button(s) Transparent, it would blend in whatever the themed color is.
    Opera also themes the back color to match on mouse over of the extra button it adds .... I have a Lenovo PC that I use, and that has a yellow background on the buttons (and title bar) that fades blue on mouse over (of the buttons) with the "black" image becoming white ... the mentioned method would not respect that, where as Opera does... ??!

    Kris

  5. #5
    Fanatic Member jdc20181's Avatar
    Join Date
    Oct 2015
    Location
    Indiana
    Posts
    1,009

    Re: Add button to the titlebar??

    Quote Originally Posted by i00 View Post
    Opera also themes the back color to match on mouse over of the extra button it adds .... I have a Lenovo PC that I use, and that has a yellow background on the buttons (and title bar) that fades blue on mouse over (of the buttons) with the "black" image becoming white ... the mentioned method would not respect that, where as Opera does... ??!

    Kris
    I am not sure, is Opera open source? See about finding a open source browser with that kind of thing on the top (its rough finding on in .NET plenty out there) My guess is its all written with custom classes etc. they probably even have their own framework.

    Edit: Found another source https://github.com/TheCodeKing/ActiveButtons.Net
    Last edited by jdc20181; Nov 7th, 2017 at 08:47 PM.
    Disclaimer: When code is given for example - it is merely a example. See my First CodeBank Submission Upgrading to the newest IE when using the Webbrowser control See my Second CodeBank SubmissionVB.NET - Recording History or changes using WebbrowserControl RichTextBox Textbox
    See my Third codebank submission VB.NET - Detecting Secure/Insecure Websites (ssl) w/ Webbrowser control See CodeBank Submission 4 A Simple Large View Calendar Control See my browser project BeffsBrowser Try my SpeedTest Project

    Unless said otherwise (e.g. From one of my projects thus, those are mostly licensed under MIT) - All Code snippets advice or otherwise that I post on this site, are expressly licensed under Creative Commons Attribution 4.0 International Please respect my copyrights.

  6. #6

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,200

    Re: Add button to the titlebar??

    Quote Originally Posted by Sitten Spynne View Post
    Rendering Controls with Visual Styles seems to be a good resource for client area controls, but I don't see much that makes me believe it will do the right thing for non-client area controls. I can't find any documentation that seems to apply to non-client rendering while respecting the visual theme.

    I do know that long ago I noticed Chrome used the Vista-style title bar even on Windows XP, so I got curious and looked at the Chromium source to find out how. It turns out the answer is "Chromium is a borderless form. If visual styles are enabled, then rather than using the normal title bar, it draws its own title bar and borders so it can look consistent across all versions of Windows." That was years ago and might have changed since then. Opera may or may not be doing the same thing.
    Option StartRant On

    I really think that M$ has dropped the 8 ball on this... I mean if Chrome etc are doing what you mention then that is also flawed... I mean if M$ change again then they (Chrome etc) will prob be Windows 10 looking "flat" Windows clashing with the newer interface look and feel.

    I think it is stupid that there are 2 window rendering methods 1 of which seems to be completely not documented. And 1 that is used for legacy MDI forms ONLY..
    Why on earth did they do this???! Why not have the VisualStyleRenderer (i.e. the theme api underlying stuff) render the new visual themes and make MDI render the same borders as the rest of the Windows Interface.

    On another note I think it is crazy that applications DPI rendering is depending on the application. It should be that any application that uses GDI can also be resized PROPERLY.. I mean when you go and draw pixel it could work out where the relative point is and draw it bigger based on the DPI... when you draw a line it could draw it smoothly between the two points specified at a higher resolution, Image could do the same if the image being rendered is bigger than the rect that it was put in at 100% DPI... etc

    Also why is GDI slow... surely this could be hardware accelerated better? (I am not even convinced that there is any hardware acceleration with it (despite what documentation states) since it is so slow).

    I sometimes wonder about some of the decisions that M$ make.

    Option StartRant Off

    Kris

  7. #7
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,025

    Re: Add button to the titlebar??

    Last night I thought it'd be cute to counter-rant but it's not. Instead, here's what I think.

    Personally, I think it's "wrong" when an application does this. But I took a tour around some modern MS apps and they're doing it in just about all of their mainstream applications, so maybe I should soften that argument. Let's talk about a "why", then stop complaining and try to solve the problem.

    It's dreadfully hard to do it from Windows Forms because WinForms was more or less abandoned around the release of Windows Vista. Understanding why is key to answering your other issues like, "Why isn't it hardware-accelerated?"

    See, WinForms is a P\Invoke wrapper and adapter around GDI. MS did an amazing amount of work to make this happen and it's truly one of their greatest engineering achievements: most of their other attempts to present WinAPI as a .NET library fell very flat.

    But that means WinForms can't do anything GDI can't do. And that list is fairly long. GDI's origins were in the 80s for at the latest Windows 3.0, maybe earlier. In that world, no one had a GPU and an 800x600 monitor was a luxury. So original GDI had some quirky rules, like, "Transparent means the form's background color, and controls shouldn't overlap." (I got that last point out of a Petzold book and I'm not 100% sure if it's true.) It wasn't hardware accelerated yet becuase GPUs didn't exist in consumer hardware. The next major overhaul I know of came in the Win2K era, though I'm sure improvements were made for Win95 and Win98. Win2K brought about some new Window Styles that allowed you to make "sort of transparent" controls that could dislpay another control beneath when they overlapped. Sort of. Alpha blending wasn't directly supported, and you had to do a bit of a dance to enable it. Some bits of GDI becamse hardware accelerated under certain circumstances, but it's not widespread and you don't "turn it on" so much as "sometimes Windows decides it can do it".

    Somewhere between ME and XP, MS realized they were facing a problem. Monitors were going to get better, and GPUs were becoming more commonplace. They wanted to allow developers to take advantage of this, but retrofitting 20-year-old GDI would be daunting. Worse, if they caused any behavioral change in WinForms at all, it would affect millions of customers. Reworking GDI would have been a choice so dangerous as to be stupid.

    So they sat down and tried to design a windowing system for 2020 in the early 2000s. "Avalon". This released with Vista and was eventually named "The Windows Presentation Foundation". It fills in many of the gaps of GDI, is hardware accelerated, and has "let the developer fully customize any control" as a core concept. The biggest news: "This is the successor to Windows Forms, you should transition to WPF when you can."

    That was the last time I remember any WinForms features being released. A handful of extra types appeared with that release, and after that MS has been hands-off with WinForms.

    Developers rejected WPF for many reasons. I think this is the most relevant:

    Microsoft had accidentally built a huge base of developers focused on enterprise applications, and those people were the main breadwinners in terms of adoption. But these people made a crucial mistake: they ignored Vista and did their best to prevent their organizations from upgrading. This persisted through Windows 7. By this point in time, MS had iterated through Silverlight and Windows Phone 8, and WPF was all but abandoned. They had a new threat in the form of iOS, and it had eaten 10% of the consumer market in 2-3 years. A bad bet on Intel meant MS was years behind.

    That brings us to a sad state today. UWP is the current recommended GUI framework for Windows. I'd be surprised if you know two people who have tried it out. I sure haven't. MS tried paying $25k bounties to get apps in the Windows Store, and got no takers. Windows 10 was given away for free for a period, and adoption was lackluster. Maybe that's why in the past few years almost every mainline MS product has been ported to MacOS and Linux, including Visual Studio. It looks suspiciously like, "If we can't sell Windows, we're not going to waste R&D on it."

    With that in mind, let's talk about pulling this off.

    Doing it in a cross-platform manner is a nightmare, which is part of why you probably don't see many applications trying this out. If you want to talk realistic customers, you have to be ready for Glass, Win8, and Win10 Windows Chrome. That goes back to Win7. I know how Chromium handled this problem: it doesn't. They don't support Win7 Glass even if you have it enabled, every window border is always solid. I don't have any not-Win10 machines to test but I suspect Office and Visual Studio are taking a similar route: they custom-render Win10 chrome on borderless windows if they aren't running on Win10. This works becuase currently, MS only "supports" Win 8.1 and Win10, and they both have very similar Windows Chrome.

    WPF had some support for mucking with the non-client area too, but it was very awkward for Glass. I think that might be part of why MS abandoned Glass in Win8, I never saw an API that made dealing with Glass borders convenient. So let's make our job easier: we aren't going to support Win7 Glass, and we're going to assume no one's using Win7.

    The good news: you have your wish and CoreApplicationViewTitleBar can be used to do anything you want with the title bar of a UWP application. The bad news: that's a UWP application and we're allergic.

    The bad news: there doesn't seem to be any new API surrounding this concept in Windows 10 or Windows 8. I thought maybe Visual Studio is using the "borderless forms" approach, but Spy++ reveals it has WS_THICKFRAME which tells me it's NOT borderless. So I can only assume it's rendering those buttons using non-client area rendering. VS seems to use its own title bar color rather than the system setting, so that makes "deciding which color to use" easy. How'd it set its own title bar color? Beats the heck out of me. No one's writing articles about customizing the look and feel of GDI apps in Windows 10. I'll keep digging.
    Nothing I post is production-ready. It is provided as-is, use it at your own risk.

  8. #8
    Frenzied Member
    Join Date
    Jun 2015
    Posts
    1,555

    Re: Add button to the titlebar??

    I promise I'm not trolling!

    Name:  chrome.jpg
Views: 46
Size:  51.4 KB
    Imagine what it would be like to set breakpoints in, or step through subclassing code;
    and then being able to hit stop/end/debug or continue, without crashing the IDE.

    VB6.tlb | Bulletproof Subclassing in the IDE

  9. #9
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,025

    Re: Add button to the titlebar??

    Huh. Maybe they added that at some point. I know for a while I couldn't get Glass working at all in Chrome, it made it stick out. Either way, as mentioned, working with Glass can be a frustrating endeavor if memory serves me right.

    Notice how they got the gradient wrong on their button. It's not the same size as the Windows buttons, and while its colors are close, it makes their button look like it's a different "shape". I'm pretty sure if there were an API-supported way to make that "look right", they'd have done it.

    I wonder what that button does if you switch to a high-contrast color scheme?
    Nothing I post is production-ready. It is provided as-is, use it at your own risk.

  10. #10
    Frenzied Member
    Join Date
    Jun 2015
    Posts
    1,555

    Re: Add button to the titlebar??

    Quote Originally Posted by Sitten Spynne View Post
    Either way, as mentioned, working with Glass can be a frustrating endeavor if memory serves me right.
    Your memory does serve you right.
    Imagine what it would be like to set breakpoints in, or step through subclassing code;
    and then being able to hit stop/end/debug or continue, without crashing the IDE.

    VB6.tlb | Bulletproof Subclassing in the IDE

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.