gtg93 Posted June 20, 2014 Posted June 20, 2014 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? Cheers
LosOjos Posted June 20, 2014 Posted June 20, 2014 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.
gtg93 Posted June 20, 2014 Author Posted June 20, 2014 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...
LosOjos Posted June 20, 2014 Posted June 20, 2014 Take a look at this example project: https://dl.dropboxusercontent.com/u/4779199/Custom%20Window%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. 1
LosOjos Posted June 20, 2014 Posted June 20, 2014 Oops... just noticed you're coding in Visual Basic. Give me 5 minutes to convert the code
gtg93 Posted June 20, 2014 Author Posted June 20, 2014 Oops... just noticed you're coding in Visual Basic. Give me 5 minutes to convert the code Cheers! Without looking, I assume that the previous example is C?
LosOjos Posted June 20, 2014 Posted June 20, 2014 Here you go, same project, this time in VB: https://dl.dropboxusercontent.com/u/4779199/Custom%20Window%20Style%20VB.zip EDIT: Cheers! Without looking, I assume that the previous example is C? C# to be precise (C# is very different to C, despite the name; it's more like Java) 1
SovietRussia Posted June 20, 2014 Posted June 20, 2014 Or just: Select your overall form Change ControlBox to false All the UI on the top disappears.
gtg93 Posted June 20, 2014 Author Posted June 20, 2014 (edited) Here you go, same project, this time in VB: https://dl.dropboxusercontent.com/u/4779199/Custom%20Window%20Style%20VB.zip Thanks - that's great... 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 ) Edited June 20, 2014 by gtg93
gtg93 Posted June 20, 2014 Author Posted June 20, 2014 Or just: I'm trying to avoid this as my OCD insists on having the icon still appear in the upper left. Changing this removes it.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now