Results 1 to 9 of 9

Thread: [urgent] "X" button

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2008
    Posts
    105

    Exclamation [urgent] "X" button

    how can i control the "X" button
    on the upper right of the Form??

    Note: Upper Right of the form...


    plsss help me

  2. #2
    Frenzied Member CoachBarker's Avatar
    Join Date
    Aug 2007
    Location
    Central NY State
    Posts
    1,121

    Re: [urgent] "X" button

    What do you mean by "control". CHeck out the post titled:

    Can I stop a form closing when the Close button is clicked?
    Thanks
    CoachBarker

    Code Bank Contribution
    Login/Manage Users/Navigate Records
    VB.Net | C#

    Helpful Links: VB.net Tutorial | C Sharp Tutorial | SQL Basics

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2008
    Posts
    105

    Re: [urgent] "X" button

    yes that's what i mean...

    is there such code that control
    the "X" button???

  4. #4
    Frenzied Member CoachBarker's Avatar
    Join Date
    Aug 2007
    Location
    Central NY State
    Posts
    1,121

    Re: [urgent] "X" button

    Post titled'

    "How to stop closing form?"
    Thanks
    CoachBarker

    Code Bank Contribution
    Login/Manage Users/Navigate Records
    VB.Net | C#

    Helpful Links: VB.net Tutorial | C Sharp Tutorial | SQL Basics

  5. #5
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: [urgent] "X" button

    Quote Originally Posted by ken_coffee
    yes that's what i mean...

    is there such code that control
    the "X" button???
    Use the FormClosing and/or the FormClosed events to do what's needed
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [urgent] "X" button

    Quote Originally Posted by JuggaloBrotha
    Use the FormClosing and/or the FormClosed events to do what's needed
    Not such a good idea. There's no way to specifically distinguish between the user clicking the Close box (as it's officially named) and your code calling Me.Close.

    Prevention is better than cure. If you don't want the user to use the Close box then it's best to disable it. There's a link in my signature that demonstrates how to do that.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: [urgent] "X" button

    Quote Originally Posted by jmcilhinney
    Not such a good idea. There's no way to specifically distinguish between the user clicking the Close box (as it's officially named) and your code calling Me.Close.

    Prevention is better than cure. If you don't want the user to use the Close box then it's best to disable it. There's a link in my signature that demonstrates how to do that.
    Well no but its very easy to implement something to check that... just a simple boolean value that you set to True when you do want the program to close works fine for me.
    Also there's the CloseReason property that is passed to the FormClosing event through the e argument that lets you determine whether the user is closing the form or if windows is shutting down the form etc.

    example:
    Code:
    Public Class Form1
        Dim letmeclose As Boolean = False
    
        Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
            If letmeclose = False Then
                e.Cancel = True
            End If
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            letmeclose = True
            Me.Close()
        End Sub
    End Class
    I do agree that most of the time prevention is better than the cure but to me disabling the X makes the program look unprofessional as you very rarely see a decent peice of software that does that... so its better for me to just make a warning message appear or something when the user clicks the X. I guess its just a personal preference though?
    Last edited by chris128; Jul 28th, 2008 at 09:53 AM.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [urgent] "X" button

    Quote Originally Posted by chris128
    Well no but its very easy to implement something to check that... just a simple boolean value that you set to True when you do want the program to close works fine for me.
    Also there's the CloseReason property that is passed to the FormClosing event through the e argument that lets you determine whether the user is closing the form or if windows is shutting down the form etc.

    example:
    Code:
    Public Class Form1
        Dim letmeclose As Boolean = False
    
        Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
            If letmeclose = False Then
                e.Cancel = True
            End If
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            letmeclose = True
            Me.Close()
        End Sub
    End Class
    All true but, regardless of any of that, prevention is better than cure. If the user can't use the Close box then it really is preferable to disable it. It's pretty annoying as a user to have something presented to you as though you can use it and then have a message pop up and say that you can't. Worse still, if you don't display a message then the user may think your app is broken because a standard piece of Windows functionality is present but doesn't do what it's supposed to do.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Jul 2008
    Posts
    105

    Re: [urgent] "X" button

    i got your points

    ^_^

    tnx alot

    u give me a real
    point of view on
    what shoud i do and not to do

    thx alot buddies

    ^_^

    more support for a newbie ^_^

    ty

Posting Permissions

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



Click Here to Expand Forum to Full Width