Results 1 to 21 of 21

Thread: New command

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2006
    Posts
    419

    New command

    ok i have a button 'New' when they click it i want it to make the picture go blank and then reset where they may of saved there last image e.g. if they did an image, saved it and now want to start a new it will wipe the picture and wipe were the quick save is to so if they saved the new image by using ctrl + S it wont overwrite there last. Hope that is clear.

  2. #2
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: New command

    Quote Originally Posted by VBlee
    ok i have a button 'New' when they click it i want it to make the picture go blank and then reset where they may of saved there last image e.g. if they did an image, saved it and now want to start a new it will wipe the picture and wipe were the quick save is to so if they saved the new image by using ctrl + S it wont overwrite there last. Hope that is clear.

    It would be a much easier to figure out what you want to do if you posted your code.
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2006
    Posts
    419

    Re: New command

    Theres to much, picture is called picCanvas, they can draw on it using bucket tool, pencil, brush etc... they can load and save images to save image i use...

    VB Code:
    1. Private Sub SaveAs_Click()
    2.  
    3.    With CommonDialog1
    4.         .CancelError = True
    5.         .DialogTitle = "Save As"
    6.         .Filter = "Windows bitmap files (*.bmp)|*.bmp"
    7.         .ShowSave
    8.         picCanvas.Picture = picCanvas.Image
    9.     End With
    10.    
    11.         SavePicture picCanvas.Picture, CommonDialog1.FileName
    12. End Sub

    what would be good is when they click New then it will erase the last image and the file name so when on the new image they click the save image it wont overwrite there last image but ask them to save it somewhere

  4. #4
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: New command

    Quote Originally Posted by VBlee
    ok i have a button 'New' when they click it i want it to make the picture go blank ...
    To reset picture in the picturebox use this:
    VB Code:
    1. Private Sub btnNew_Click()
    2.     Set Picture1.Picture = Nothing
    3. End Sub

  5. #5
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: New command

    VB Code:
    1. 'Clear Picture
    2. picCanvas.Cls
    3.  
    4. 'To stop them overwriting an existing file use
    5. CommonDialog1.Flags = cdlOFNOverwritePrompt Or cdlOFNPathMustExist
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

  6. #6

  7. #7
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: New command

    I know I've changed it since.
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

  8. #8
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: New command

    Quote Originally Posted by VBlee
    Theres to much, picture is called picCanvas, they can draw on it using bucket tool, pencil, brush etc... they can load and save images to save image i use...

    VB Code:
    1. Private Sub SaveAs_Click()
    2.  
    3.    With CommonDialog1
    4.         .CancelError = True
    5.         .DialogTitle = "Save As"
    6.         .Filter = "Windows bitmap files (*.bmp)|*.bmp"
    7.         .ShowSave
    8.         picCanvas.Picture = picCanvas.Image
    9.     End With
    10.    
    11.         SavePicture picCanvas.Picture, CommonDialog1.FileName
    12. End Sub

    what would be good is when they click New then it will erase the last image and the file name so when on the new image they click the save image it wont overwrite there last image but ask them to save it somewhere

    To erase a picture from a Picturebox:

    VB Code:
    1. picCanvas.Picture = Nothing


    If you want to reset the location that the file is to be resaved you can just use:

    VB Code:
    1. .FileName ="C\*.*"

    But You can just check to see if the file exists before you save it:

    VB Code:
    1. Function FileExists(FileName As String) As Boolean
    2.     On Error GoTo ErrorHandler
    3.     ' get the attributes and ensure that it isn't a directory
    4.     FileExists = (GetAttr(FileName) And vbDirectory) = 0
    5. ErrorHandler:
    6.     ' if an error occurs, this function returns False
    7. End Function

    If it exists just append a number or a letter to the file name and try again.
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  9. #9
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: New command

    Quote Originally Posted by Mark Gambo
    To erase a picture from a Picturebox:
    But You can just check to see if the file exists before you save it:
    Why bother, he is using a CommonDialog so.
    VB Code:
    1. CommonDialog1.Flags = cdlOFNOverwritePrompt
    That will tell you if the file exists.
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2006
    Posts
    419

    Re: New command

    Thank you all for posting, will try them all to see if i can get it going.

  11. #11

  12. #12
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: New command

    I know VBlee was talking about an Image so I added Picture/Image and posted it. Then I thought you can't Cls an Image but you have posted straight after. So you could use.
    VB Code:
    1. Set Image1.Picture = Nothing
    2. 'or
    3. Image1.Picture = LoadPicture("")
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2006
    Posts
    419

    Re: New command

    none of these work, every time i load a pictue and click new it makes the canvas blank but is i was to draw sommert n save on there it would then overwrite the file i had before.

  14. #14

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2006
    Posts
    419

    Re: New command

    so how would i set the file name as untitled or something like that as when i have tried as i am unsure of how to put about the filename function it went wrong.

  16. #16

  17. #17

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2006
    Posts
    419

    Re: New command

    hmmm, when i have loaded one and then created a new and pressed save it still comes up with the old file name, and then if i click cancel it says i have an error on this line...

    VB Code:
    1. SavePicture picCanvas.Picture, CommonDialog1.FileName

  18. #18
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: New command

    If you hit the Cancel button on your CommonDialog then FileName becomes invalid and therfore SavePicture generates error...
    You may need to set CancelError = True and also create some basic error handler. Tons of samples are available throughout the forum.

  19. #19
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: New command

    In case you can't find here is general idea:
    VB Code:
    1. Private Sub Command1_Click()
    2.  
    3. On Error GoTo ErrHandler
    4.  
    5.     With CommonDialog1
    6.         '...
    7.         .CancelError = True
    8.         '...
    9.     End With
    10.    
    11.     Exit Sub
    12.    
    13. ErrHandler:
    14.  
    15.     'resume or exit procedure - your choice
    16.     Resume Next
    17.  
    18. End Sub

  20. #20

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2006
    Posts
    419

    Re: New command

    silly me... i did have the CancelError = True but i forgot to put what happens if theres an error so it crashed... fixed that now

  21. #21
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: New command

    Quote Originally Posted by VBlee
    none of these work, every time i load a pictue and click new it makes the canvas blank but is i was to draw sommert n save on there it would then overwrite the file i had before.
    This is why I told you to use
    VB Code:
    1. CommonDialog1.Flags = cdlOFNOverwritePrompt
    This will tell you if the file exists and do you want to overwrite.
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

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