Jump to content

Removing the Close X from my app in Visual Basic (MS Visual Studio 2013)


Recommended Posts

Posted

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?

 

Printers.png

 

Cheers

Posted

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.

Posted
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...
Posted

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. :)

  • Thanks 1
Posted
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?

Posted
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.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...