|
-
Oct 16th, 2006, 03:10 PM
#1
Thread Starter
Hyperactive Member
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.
-
Oct 16th, 2006, 03:14 PM
#2
Re: New command
 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."
-
Oct 16th, 2006, 03:24 PM
#3
Thread Starter
Hyperactive Member
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:
Private Sub SaveAs_Click()
With CommonDialog1
.CancelError = True
.DialogTitle = "Save As"
.Filter = "Windows bitmap files (*.bmp)|*.bmp"
.ShowSave
picCanvas.Picture = picCanvas.Image
End With
SavePicture picCanvas.Picture, CommonDialog1.FileName
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
-
Oct 16th, 2006, 03:28 PM
#4
Re: New command
 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:
Private Sub btnNew_Click()
Set Picture1.Picture = Nothing
End Sub
-
Oct 16th, 2006, 03:31 PM
#5
Re: New command
VB Code:
'Clear Picture
picCanvas.Cls
'To stop them overwriting an existing file use
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.
-
Oct 16th, 2006, 03:34 PM
#6
Re: New command
 Originally Posted by Keithuk
VB Code:
'Clear image/Picture
picCanvas.Cls
That would only clear Image - not Picture. Picture is an object so it has to be set to Nothing in order to clear it.
-
Oct 16th, 2006, 03:35 PM
#7
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.
-
Oct 16th, 2006, 03:35 PM
#8
Re: New command
 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:
Private Sub SaveAs_Click()
With CommonDialog1
.CancelError = True
.DialogTitle = "Save As"
.Filter = "Windows bitmap files (*.bmp)|*.bmp"
.ShowSave
picCanvas.Picture = picCanvas.Image
End With
SavePicture picCanvas.Picture, CommonDialog1.FileName
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:
picCanvas.Picture = Nothing
If you want to reset the location that the file is to be resaved you can just use:
But You can just check to see if the file exists before you save it:
VB Code:
Function FileExists(FileName As String) As Boolean
On Error GoTo ErrorHandler
' get the attributes and ensure that it isn't a directory
FileExists = (GetAttr(FileName) And vbDirectory) = 0
ErrorHandler:
' if an error occurs, this function returns False
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."
-
Oct 16th, 2006, 03:41 PM
#9
Re: New command
 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:
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.
-
Oct 16th, 2006, 03:54 PM
#10
Thread Starter
Hyperactive Member
Re: New command
Thank you all for posting, will try them all to see if i can get it going.
-
Oct 16th, 2006, 03:57 PM
#11
Re: New command
 Originally Posted by Keithuk
I know I've changed it since.
I noticed that ... but you left Picture instead of Image ...
-
Oct 17th, 2006, 03:42 PM
#12
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:
Set Image1.Picture = Nothing
'or
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.
-
Oct 17th, 2006, 05:36 PM
#13
Thread Starter
Hyperactive Member
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.
-
Oct 17th, 2006, 06:15 PM
#14
Re: New command
It will overwrite if you won't specify new file name...
-
Oct 17th, 2006, 06:23 PM
#15
Thread Starter
Hyperactive Member
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.
-
Oct 17th, 2006, 06:32 PM
#16
Re: New command
Keithuk already showed you that in his replies (posts #5 and #9).
-
Oct 17th, 2006, 06:37 PM
#17
Thread Starter
Hyperactive Member
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:
SavePicture picCanvas.Picture, CommonDialog1.FileName
-
Oct 17th, 2006, 06:47 PM
#18
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.
-
Oct 17th, 2006, 06:50 PM
#19
Re: New command
In case you can't find here is general idea:
VB Code:
Private Sub Command1_Click()
On Error GoTo ErrHandler
With CommonDialog1
'...
.CancelError = True
'...
End With
Exit Sub
ErrHandler:
'resume or exit procedure - your choice
Resume Next
End Sub
-
Oct 17th, 2006, 06:54 PM
#20
Thread Starter
Hyperactive Member
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
-
Oct 18th, 2006, 02:29 PM
#21
Re: New command
 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:
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|