locked
I want a window to show up that says... RRS feed

  • Question

  • Hello all,

    I got a question for you awesome code guru’s out there!

    I want to see if a directory exists on my computer. If it does, I want a message box that says “Directory Exists” and also the message box should have both an OK button and an Exit button.

    I know if I put msgbox(“The Directory Exists”) I get want I want. HOWEVER that only shows an OK button. How can I get another button here that says “Exit” and when I select “Exit” it will kill the program but when I hit the OK button it continues on with the rest of my program.

    This is what I got so far...

    If

    My.Computer.FileSystem.DirectoryExists("C:\ProgramFiles\CA\Unicenter Software Delivery") Then

    I need something right here!!!!

    End If

    Any ideas would be great! Thanks so much!

    Chapio
    Thursday, September 21, 2006 6:53 PM

Answers

  • There unfortunately isn't an "Exit" button available in the MessageBoxButtons. You could create your own message box, highly customizing a form to look/act like a MessageBox.

     

    if My.Computer.FileSystem.DirectoryExists("C:\dsfsdfdsfdsfdsfsfs") then

       MessageBox.Show("Directory specified exists!", "Directory Exists", MessageBoxButton.OK, MessageBoxIcon.Information)

    else

       MessageBox.Show("Directory specified does not exist", "Directory Not Found", MessageBoxButton.OK, MessageBoxIcon.Error) 

    end if

     

    you could have an OK/Cancel button but I believe, and have looked, there is no Exit button available - best thing to do would be to again, create a MessageBox of your own (new form) and make it look/feel/act like a MessageBox

    Thursday, September 21, 2006 7:10 PM
  • in that case, as suggested, you would determine the button pressed:

     

    if MessageBox.Show("sdfdsf", "dsfsdf", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = Windows.Forms.DialogResult.OK then 'OK button was press

       'do whatever as they pressed ok

    else

       'do whatever as they press No

    end if

    Thursday, September 21, 2006 7:33 PM

All replies

  • There unfortunately isn't an "Exit" button available in the MessageBoxButtons. You could create your own message box, highly customizing a form to look/act like a MessageBox.

     

    if My.Computer.FileSystem.DirectoryExists("C:\dsfsdfdsfdsfdsfsfs") then

       MessageBox.Show("Directory specified exists!", "Directory Exists", MessageBoxButton.OK, MessageBoxIcon.Information)

    else

       MessageBox.Show("Directory specified does not exist", "Directory Not Found", MessageBoxButton.OK, MessageBoxIcon.Error) 

    end if

     

    you could have an OK/Cancel button but I believe, and have looked, there is no Exit button available - best thing to do would be to again, create a MessageBox of your own (new form) and make it look/feel/act like a MessageBox

    Thursday, September 21, 2006 7:10 PM
  • else

       MessageBox.Show("Directory specified does not exist", "Directory Not Found", MessageBoxButton.OK, MessageBoxIcon.Error) 

    end if

     

    An alternative would be

     

    else

    Dim sts As Integer = _

    MessageBox.Show("The directory does not exist, Do you want to exit?", "No Such directory", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)

    If sts = System.Windows.Forms.DialogResult.Yes Then Application.Exit()

    end if

    No custom dialogue needed.

     

    Thursday, September 21, 2006 7:25 PM
  • Thanks for the reply!  I was thinking I could create a new form!  However, I really don't know how to do that just yet.  What I am trying to do is see if a program is installed on a computer.  If it is, I want a message box to show up that says:

    "Program is installed.  Would you like to Uninstall it?"

    I noticed that you can have a "Yes" or a "No" for the MessageBoxButton.

    So if you click on "Yes" It will start a process to uninstall the program which is just a simple command.  If you click on "No" the program will be aborted.

    So far, I got this:


    If My.Computer.FileSystem.DirectoryExists("C:\Program Files\CA\Unicenter Software Delivery") Then

    MessageBox.Show("ShipIt is already installed! Would you like to uninstall the program?", "ShipIt Exists", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)

    Or would this be easier in loading and creating a new form?
    Thursday, September 21, 2006 7:27 PM
  • in that case, as suggested, you would determine the button pressed:

     

    if MessageBox.Show("sdfdsf", "dsfsdf", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = Windows.Forms.DialogResult.OK then 'OK button was press

       'do whatever as they pressed ok

    else

       'do whatever as they press No

    end if

    Thursday, September 21, 2006 7:33 PM