Disabling the close button of a windows application has a problem

When I tried to disable the close button of my Windows Application program using an unmanaged code, this red close button will appear again if I maximized, minimized it , or using Win(key) + D (and again)

I don't know why...

I can delete the Close menu item, but rather, I wanna disable it.

So, if you please find the solution, thanks...



Answer this question

Disabling the close button of a windows application has a problem

  • Patrick Martineau

    What happens if you do it in HandleCreated event handler

  • Jeffrey van Gogh - MSFT

    like Enablemenu()
  • Art Vandolay Jr.

    Good to hear that you find solution! OnResize() also can help here, just like LayoutChanged.

    HandleCreated will be called when internal WinForms stuff decide that it need new HWND. As far as I know this happens when you change some styles, like Border (WinForms will create new Win32 window with new borders).



  • Kulwant Dhaliwal

    I used the Win32 API functions
  • kwarnke

    Set the forms controlbox property to false...this will get rid of the minimize, maximize and close buttons in the upper right hand corner of the window

    HTH



  • danoliv

    Hi SG,

    After 2 days of studying , and after I tried the HandleCreated event, the latter couldn't help me, cause I notice that the handle of the window is created once all through the application and destroyed finally when the form is disposed.

    So, I tried the LayoutChanged event, and I found that it's great, cause when we maximize, minimize the form, this event is triggered by the form. So I can insert a condition and use a property in addition to a call to my code that manage the disabling of the close button.

  • Dennis Cheng

    Yes, you can, VB can do same things like C#.

    What Win32 API do you use



  • Bill Richardson

    Can I do this in Visual Basic, as you know I'm using it

    Can I


  • arup08

    Ok, I'll see

    I've to write the code and dig into this handler to see how can I manage it.

    I'll reply to you later. Btw, 10x


  • Sergey Jmacov

    How you tried to disable it by unmanaged code

  • Jeff Guenthner

    Hi!

    Windows Forms will recreate window handle from time to time, so if you turn something off, you must do it again in HandleCreated event.



  • Richard Waymire - MSFT

    Hii , thanks for the cooperation, but I wanna see the control box, (I know this property), but I want to see the maximize, minimize and the close button disabled

    could you help me plz...


  • Disabling the close button of a windows application has a problem