Coding Thread, Removing the Close X from my app in Visual Basic (MS Visual Studio 2013) in Coding and Web Development; I've put together a basic "add/remove/default printer" application for use by staff inMS Visual Studio 2013 using Visual Basic. I ...
20th June 2014, 11:16 AM #1
Removing the Close X from my app in Visual Basic (MS Visual Studio 2013)
I've put together a basic "add/remove/default printer" application for use by staff inMS Visual Studio 2013 using Visual Basic. I was just curious if there is any way anyone is aware of to remove the Windows Close X in the top right?
I know I can remove the "Control Box" by simply setting a True to False, but that removes the icon at the top left as well, and I'm being a little OCD about it... Any one aware of a bit of code or even something in the designer side to do this?
20th June 2014, 12:26 PM #2
You can do it, but not using the default window styles in VS.
The 'standard' way (as in uses Windows SDK classes) would to override the form's 'CreateParms' function, which will allow you to specify any of the Windows Styles constants. You can use "CS_NO_CLOSE" (it's hex is 0x20) to disable the close button that way, note though I say disable, not remove! Let me know if you want example code for this method.
The harder but ultimately more customisable way is to create your own window style on a borderless form. It's a bit of work, but ultimately gives you most freedom over design. You'll want to set the 'FormBorderStyle' property to none, then draw on you title bar as you see fit. You''l lose default actions like resizing (though it looks like you're making a fixed size form anyway) and moving, so you'll have to code that functionality in yourself. This is the method I'd choose and can give you some sample code for window movement using a DIY title bar made from a label.
20th June 2014, 12:37 PM #3
It'd be great if you could give me some sample code to allow window movement? I'm new to VB and coding in general to be honest, but thought this would be a good way to learn some more of the basics whilst actually creating something we need...
20th June 2014, 12:41 PM #4
Take a look at this example project: https://dl.dropboxusercontent.com/u/...%20Example.zip
Essentially, we have a borderless form (you can simply change the form in your current project to match this) with a label at the top called 'TitleBar'. the icon on mine is huge, but you can shrink yours down to the stand 16x16 for 'authenticity'. You then simply monitor mouse actions on the label, moving the whole form if the mouse is held down on it.
This is very basic and of course you can take it much further, but it should get you started on the idea.
20th June 2014, 12:45 PM #5
Oops... just noticed you're coding in Visual Basic. Give me 5 minutes to convert the code
20th June 2014, 12:55 PM #6
Cheers! Without looking, I assume that the previous example is C?
Originally Posted by LosOjos
20th June 2014, 12:58 PM #7
Here you go, same project, this time in VB: https://dl.dropboxusercontent.com/u/...Style%20VB.zip
C# to be precise (C# is very different to C, despite the name; it's more like Java)
Originally Posted by gtg93
20th June 2014, 01:03 PM #8
Select your overall form
Change ControlBox to false
All the UI on the top disappears.
20th June 2014, 01:03 PM #9
Thanks - that's great...
Originally Posted by LosOjos
I may have a look at the C# one too... I plan to have a dabble with that eventually too
EDIT - This worked brilliantly - thanks! (my photoshop skills for the titlebar need some improvement though )
Last edited by gtg93; 20th June 2014 at 02:34 PM.
20th June 2014, 01:05 PM #10
I'm trying to avoid this as my OCD insists on having the icon still appear in the upper left. Changing this removes it.
Originally Posted by SovietRussia
By BatchFile in forum Windows Server 2000/2003
Last Post: 6th September 2011, 04:30 PM
By jonnyfive in forum Scripts
Last Post: 22nd April 2011, 03:50 PM
By timbo343 in forum Windows 7
Last Post: 5th March 2011, 05:11 PM
Last Post: 21st September 2006, 01:54 PM
By Roger in forum Windows
Last Post: 5th October 2005, 06:01 AM
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)