Results 1 to 4 of 4

Thread: Common Dialog problems.

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2002
    Location
    England
    Posts
    242

    Common Dialog problems.

    ive added a common dialog control onto my project, but there are a few things im stuck with:
    1) i have a browse button but i dont know how to change the picture in a image control with the file that was selected.
    here is the code i have so far:
    Lpeek

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Nov 2002
    Location
    England
    Posts
    242
    whoops, pressed enter to quickly.
    here is the code for q 1)
    VB Code:
    1. Private Sub cmdbgbrowse_Click()
    2.     diabox.DialogTitle = "Browse"
    3.     diabox.Filter = "All Formats|*.BMP;*.RLE;*.DIB;*.GIF;*.JPG;*.JPEG;*.JPE;*.PNG;*.TIF;*.TIFF|BMP (*.BMP;*.RLE;*.DIB)|*.BMP;*.RLE;*.DIB|GIF (*.GIF)|*.GIF|JPEG (*.JPG;*.JPEG;*.JPE)|*.JPG;*.JPEG;*.JPE|PNG (*.PNG)|*.PNG|TIFF (*.TIF;*.TIFF)|*.TIF;*.TIFF|"
    4.     diabox.ShowOpen
    5.     picturepreview = diabox.FileName
    6.     imgpic.Picture = picturepreview
    7. End Sub
    but that doesnt work right.

    2) i call the dialog in the Save As menu thing, but i dont know how to make it so if a file already exists then you have the msgbox to either overwrite or to exit.
    here is my code so far:
    [Highlight=VB]
    Private Sub saveas_Click()
    diabox.DialogTitle = "Save Scene As"
    diabox.Filter = "Scene Files (*.tsn)|*.tsn|"
    diabox.ShowSave
    'save the file
    Open App.Path & "\Demo\Scenes\" & diabox.FileTitle For Output As #1
    Print #1, diabox.FileTitle & vbNewLine & txtscenetext.Text & vbNewLine & txtnorth.Text & vbNewLine & txtsouth.Text & vbNewLine & txteast.Text & vbNewLine & txtwest.Text
    Close #1
    done:
    End Sub

    3) how do i make it so if the user clicks cancel it just quits the dialog? because what i have at the moment, is that it saves weather i click save or cancel.

    4) how do i erase what is in the FileName box of the dialog? because when i close a dialog is has something in it, so next time i open the dialog it already has that in it. and this code doesnt work:
    VB Code:
    1. diabox.FileTitle = ""

    thanks
    Lpeek

  3. #3
    Fanatic Member laserman's Avatar
    Join Date
    Jan 2002
    Location
    Wales U.K
    Posts
    775
    Use loadpicture command.
    This is just a sample piece.

    Add the loadpicture to your code]

    VB Code:
    1. Private Sub Command1_Click()
    2. Dialog1.Filter = "*.jpeg|*.bmp|*.gif|"
    3. Dialog1.ShowOpen
    4. Image1.Picture = LoadPicture(Dialog1.FileName)
    5.  
    6. 'ps set Cancelerror to true in the dialog properties'

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    2) See help for the "Flags" property, one of the options is to show the "confirm overwrite" message.

    3) Set the CancelError property - then you will get an error if they cancel. eg:
    VB Code:
    1. Private Sub saveas_Click()
    2.     diabox.DialogTitle = "Save Scene As"
    3.     diabox.Filter = "Scene Files (*.tsn)|*.tsn|"
    4.     diabox.CancelError = True
    5.     On Error Resume Next
    6.     diabox.ShowSave
    7.     If Err = 0 Then
    8.       On Error Goto 0    '(resume normal error handling)
    9.       'save the file
    10.       Open App.Path & "\Demo\Scenes\" & diabox.FileTitle For Output As #1
    11.       Print #1, diabox.FileTitle & vbNewLine & txtscenetext.Text & vbNewLine & txtnorth.Text & vbNewLine & txtsouth.Text & vbNewLine & txteast.Text & vbNewLine & txtwest.Text
    12.       Close #1
    13.    End If
    14. done:
    15. End Sub

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