Results 1 to 8 of 8

Thread: closing messagebox automatically

  1. #1

    Thread Starter
    Hyperactive Member Bananafish's Avatar
    Join Date
    Jan 2001
    Posts
    394

    closing messagebox automatically

    does anyone know how to close a messagebox automatically?

    (without the using clicking it)

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    You need some sort of subclassing , but why don't you take the easier path and make your own custom message box with a timer .

  3. #3

    Thread Starter
    Hyperactive Member Bananafish's Avatar
    Join Date
    Jan 2001
    Posts
    394
    Pirate - thanks for the reply.

    I can't use a timer - as
    a) I don't know how long to display the messagebox before closing it.
    b) I wish to retrospectively incorporate the functionality into the application and so would rather not create my own messagebox class at this point (although I like your thinking).

    Effectively what I am doing is recognising that the application hasbn't been used for a given amount of time and displaying a user password screen - however if the user changes I need to close all the children (and other modally displayed) forms.

    This is fine I can do this - however I also wish to close down any messageboxes. The problem I have is that when I close the form that requested the messagebox - the messagebox terminates with a "No" (even if it only has a Cancel and Yes button). Mostly this is ok - but It can give unexpected results (such as aborting) depending on the code that follows the messagebox.

  4. #4
    Addicted Member PeteD's Avatar
    Join Date
    Jun 2003
    Location
    Sydney
    Posts
    158
    You could have a class with a shared Public flag:

    e.g.

    Public Class SomeClass
    Public Shared ApplicationIsTerminating() as Boolean
    End class

    and when your application is being closed (or your forms are being closed) set SomeClass.ApplicationIsTerminating = True

    When you show a messagbox, use something like the following:

    Dim msgboxResult As Windows.Forms.DialogResult = Windows.Forms.MessageBox.Show("Your message", "Your caption", MessageBoxButtons.OKCancel)

    If Not SomeClass.ApplicationIsTerminating Then
    If msgboxResult = DialogResult.OK Then
    ' OK processing
    ElseIf msgboxResult = DialogResult.Cancel Then
    ' Cancel processing
    End If
    Else
    'Take a different course of action
    End If

  5. #5
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    hmm lets see... wanna try this?
    make a sub that would call the messagebox. Call that sub by declaring a new thread... try terminating the thread and see if the messagebox closes
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  6. #6

    Thread Starter
    Hyperactive Member Bananafish's Avatar
    Join Date
    Jan 2001
    Posts
    394
    yes that'll work.

    Thanks Mr. Polite. I knew there would be some lateral thinking in there somewhere.

  7. #7
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Of course you could always make your own Messagebox form and have full controll over it.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  8. #8
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Originally posted by Cander
    Of course you could always make your own Messagebox form and have full controll over it.
    yeah that;s cool too. Edneeis had an example how to make a form and call it like a messagebox (so it would return the selected value and stuff like that). you may find it if you search
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

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