+ Post New Thread
Results 1 to 10 of 10
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 ...
  1. #1
    gtg93's Avatar
    Join Date
    May 2010
    Posts
    330
    Thank Post
    204
    Thanked 42 Times in 34 Posts
    Rep Power
    16

    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?

    Printers.png

    Cheers

  2. #2

    LosOjos's Avatar
    Join Date
    Dec 2009
    Location
    West Midlands
    Posts
    5,498
    Thank Post
    1,456
    Thanked 1,201 Times in 814 Posts
    Rep Power
    712
    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.

  3. #3
    gtg93's Avatar
    Join Date
    May 2010
    Posts
    330
    Thank Post
    204
    Thanked 42 Times in 34 Posts
    Rep Power
    16
    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...

  4. #4

    LosOjos's Avatar
    Join Date
    Dec 2009
    Location
    West Midlands
    Posts
    5,498
    Thank Post
    1,456
    Thanked 1,201 Times in 814 Posts
    Rep Power
    712
    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.

  5. Thanks to LosOjos from:

    gtg93 (20th June 2014)

  6. #5

    LosOjos's Avatar
    Join Date
    Dec 2009
    Location
    West Midlands
    Posts
    5,498
    Thank Post
    1,456
    Thanked 1,201 Times in 814 Posts
    Rep Power
    712
    Oops... just noticed you're coding in Visual Basic. Give me 5 minutes to convert the code

  7. #6
    gtg93's Avatar
    Join Date
    May 2010
    Posts
    330
    Thank Post
    204
    Thanked 42 Times in 34 Posts
    Rep Power
    16
    Quote Originally Posted by LosOjos View Post
    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?

  8. #7

    LosOjos's Avatar
    Join Date
    Dec 2009
    Location
    West Midlands
    Posts
    5,498
    Thank Post
    1,456
    Thanked 1,201 Times in 814 Posts
    Rep Power
    712
    Here you go, same project, this time in VB: https://dl.dropboxusercontent.com/u/...Style%20VB.zip

    EDIT:
    Quote Originally Posted by gtg93 View Post
    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)

  9. Thanks to LosOjos from:

    gtg93 (20th June 2014)

  10. #8
    SovietRussia's Avatar
    Join Date
    Mar 2013
    Location
    Powys, Wales
    Posts
    642
    Thank Post
    70
    Thanked 145 Times in 111 Posts
    Rep Power
    47
    Or just:

    Select your overall form
    Change ControlBox to false
    All the UI on the top disappears.

    yeah.png

  11. #9
    gtg93's Avatar
    Join Date
    May 2010
    Posts
    330
    Thank Post
    204
    Thanked 42 Times in 34 Posts
    Rep Power
    16
    Quote Originally Posted by LosOjos View Post
    Here you go, same project, this time in VB: https://dl.dropboxusercontent.com/u/...Style%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 )

    Add Printers.png
    Last edited by gtg93; 20th June 2014 at 02:34 PM.

  12. #10
    gtg93's Avatar
    Join Date
    May 2010
    Posts
    330
    Thank Post
    204
    Thanked 42 Times in 34 Posts
    Rep Power
    16
    Quote Originally Posted by SovietRussia View Post
    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.

SHARE:
+ Post New Thread

Similar Threads

  1. Remove the DC role from a server
    By BatchFile in forum Windows Server 2000/2003
    Replies: 5
    Last Post: 6th September 2011, 04:30 PM
  2. Replies: 13
    Last Post: 22nd April 2011, 03:50 PM
  3. Remove the Sharing tab from folder properties
    By timbo343 in forum Windows 7
    Replies: 1
    Last Post: 5th March 2011, 05:11 PM
  4. Removing Linux from my PDA
    By dezt in forum *nix
    Replies: 7
    Last Post: 21st September 2006, 01:54 PM
  5. Replies: 10
    Last Post: 5th October 2005, 06:01 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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