-
pretty simple question hopefully
ok how would i make it so when you click the command button an image pops up, i want to make it so when you click the command button about 20 of the same or different (doesnt matter) images appear on your screen on desktop.
i am using vb6, thanks for looking and please help.
-
Re: pretty simple question hopefully
what kind of images are you referring to? when you say Desktop do you mean changing your background image? or did you mean to say form instead?
-
Re: pretty simple question hopefully
Quote:
Originally Posted by VBNubcake
what kind of images are you referring to? when you say Desktop do you mean changing your background image? or did you mean to say form instead?
no i dont mean changing your desktop backround, so i guess i mean form, and im referring to like maybe a small smiley face or something? sorry im pretty new to visual basic :\
-
Re: pretty simple question hopefully
Welcome to the forum Trevor.
If you're referring to your Form, you can load your images into a PictureBox array. Here's an example. Put a CommandButton and a PictureBox on your Form. In the PropBox make the PictureBox.Index = 0. Your next step will be to load your images in the PictureBox array with the .Picture property.
Code:
Option Explicit
Private Sub Form_Load()
Picture1(0).Visible = False
End Sub
Private Sub Command1_Click()
Dim i%
Picture1(0).Visible = True
For i% = 1 To 5
Load Picture1(i%)
Picture1(i%).Top = Picture1(0).Top + 500 * i%
Picture1(i%).Visible = True
Next
End Sub
-
Re: pretty simple question hopefully
Quote:
Originally Posted by CDRIVE
Welcome to the forum Trevor.
If you're referring to your Form, you can load your images into a PictureBox array. Here's an example. Put a CommandButton and a PictureBox on your Form. In the PropBox make the PictureBox.Index = 0. Your next step will be to load your images in the PictureBox array with the
.Picture property.
Code:
Option Explicit
Private Sub Form_Load()
Picture1(0).Visible = False
End Sub
Private Sub Command1_Click()
Dim i%
Picture1(0).Visible = True
For i% = 1 To 5
Load Picture1(i%)
Picture1(i%).Top = Picture1(0).Top + 500 * i%
Picture1(i%).Visible = True
Next
End Sub
ok but wouldnt that make it appear on your vb program? i want it to appear at random places on your screen not just viewing the image on the form
-
Re: pretty simple question hopefully
Quote:
Originally Posted by trevor267
ok but wouldnt that make it appear on your vb program? i want it to appear at random places on your screen not just viewing the image on the form
Someone else may be able to give you a better solution, but the only one I can think of is to use multiple forms. Then you can set all the form's BorderStyle to none and size your picturebox and image to fill all the area of each form. The result will appear as an images only. Btw, you can experiment to see how this looks without writing a single line of code. Just set it up in the prop box. You can also import your picture from properties.
EDIT: Come to think of it, if you go this way you don't need a PictureBox on the forms. You can put your images directly on the forms.
-
Re: pretty simple question hopefully
Quote:
Originally Posted by CDRIVE
Someone else may be able to give you a better solution, but the only one I can think of is to use multiple forms. Then you can set all the form's BorderStyle to none and size your picturebox and image to fill all the area of each form. The result will appear as an images only. Btw, you can experiment to see how this looks without writing a single line of code. Just set it up in the prop box. You can also import your picture from properties.
EDIT: Come to think of it, if you go this way you don't need a PictureBox on the forms. You can put your images directly on the forms.
thank you very much you are very helpfull :)
-
Re: pretty simple question hopefully
Quote:
Originally Posted by trevor267
thank you very much you are very helpfull :)
You are quite welcome Trevor. I'm curious though, as to why none of the Gurus have answered this post? :confused: By the way, I tried this my self by using my avatar, which is actually by business logo. I sized the form to the exact same size as the logo and put the code in a timer event using Form.Top and Form.Left to make it drift diagonally across my desk top. The effect was kind of creepy! ;)
-
Re: pretty simple question hopefully
Quote:
Originally Posted by CDRIVE
You are quite welcome Trevor. I'm curious though, as to why none of the Gurus have answered this post? :confused: By the way, I tried this my self by using my avatar, which is actually by business logo. I sized the form to the exact same size as the logo and put the code in a timer event using Form.Top and Form.Left to make it drift diagonally across my desk top. The effect was kind of creepy! ;)
Here's the code I used for motion. The Form sizing was done manualy at designe time. Imagine multiple images moving around randomly.
Code:
Option Explicit
Private Sub Form_Load()
Timer1.Interval = 50
End Sub
Private Sub Timer1_Timer()
Static i%
i% = i% + 10
Form1.Left = i%
Form1.Top = i%
End Sub
-
Re: pretty simple question hopefully
used that,
i get
runtime error '380':
invalid property value
-
Re: pretty simple question hopefully
Quote:
Originally Posted by trevor267
used that,
i get
runtime error '380':
invalid property value
What line throws the error? Did you put a Timer and a Picture directly on your Form? I didn't use a PictureBox with this code.
Edit: I doubt that this has anything to do with your error problem, but I just discovered that I have a problem here myself. The Form_Load code is not working for me. I thought it was working because I had sized the Form and set the BorderStyle manualy at design time, and then added that code to the Form_Load event afterwards so you wouldn't have to do it manualy. For some reason my code is being ignored. In other words, I can set the BorderStyle in the PropBox to 0 and that works but not at Run Time. If I can't find the problem here i may have to post my own question.
Edit2: Just read the VS help files and discovered that the Style property is Read Only at Run Time. So it must be set in the PropBox at design time.
-
Re: pretty simple question hopefully
didnt understand the last part :\ but i really thank you for coming back here every time i ask a question, your really helping me a lot
-
Re: pretty simple question hopefully
Quote:
Originally Posted by trevor267
didnt understand the last part :\ but i really thank you for coming back here every time i ask a question, your really helping me a lot
The last part of my post referred to the Style (Form1.Style) property of the Form. The Style '0' property sets the Form border to none. This means that it will have no Title Bar and no Border. This property is Read Only at Run Time, so it can't be written in code. Properties that are Read only at run time must be set in the Properties window at Design Time.
To see an example of what I'm describing, open a new project and go to the Form1 properties window. Scroll down to the fifth item, which is BorderStyle. Select 0-None and then run the program. You should see a Form with no border and no Title Bar.
Let me know what you see.
-
Re: pretty simple question hopefully
Quote:
Originally Posted by CDRIVE
The last part of my post referred to the Style (Form1.Style) property of the Form. The Style '0' property sets the Form border to none. This means that it will have no Title Bar and no Border. This property is Read Only at Run Time, so it can't be written in code. Properties that are Read only at run time must be set in the Properties window at Design Time.
To see an example of what I'm describing, open a new project and go to the Form1 properties window. Scroll down to the fifth item, which is BorderStyle. Select 0-None and then run the program. You should see a Form with no border and no Title Bar.
Let me know what you see.
oh cool thank you, that could be helpfull sometime :)
-
Re: pretty simple question hopefully
Ok Trevor, I've re-written the code and this should work for you. In your Vb Graphics folder you should find a Bitmap named "Happy.bmp". It's a happy face. To put it into your PictureBox, go to the Properties window/Picture1 then scroll down to the Picture property. Click on the little button and navigate to Graphics/Assorted folder to find and select Happy.bmp. Then follow the comments in the code.
Let me know how it goes. It worked fine for me.
Code:
' From the Tool box: Put a Timer and a PictureBox on your Form.
' From the Properties window: Set the Form WindowStyle to (None) 0 and the form
' StartUpPosition to (Manual) 0.
Option Explicit
Private Sub Form_Load()
Picture1.BorderStyle = 0 'Set Picture1 Border to none.
Picture1.AutoSize = True 'AutoSize the Picture1 to the picture size
Picture1.Left = Me.Left 'Align left edge of Picture1 to left edge of Form
Picture1.Top = Me.Top 'Align top edge of Picture1 to top edge of Form
Me.Width = Picture1.Width 'Make Form width equal to Picture1 width
Me.Height = Picture1.Height 'Make Form height equal to Picture1 height
Timer1.Interval = 50
End Sub
Private Sub Timer1_Timer()
Static i% 'Create a counter
i% = i% + 10 'Add 10 to the count every 50mSec
Me.Left = i% 'Move Form left by the value of i% every 50mSec
Me.Top = i% 'Move Form down by the value of i% every 50mSec
End Sub
-
Re: pretty simple question hopefully
Quote:
Originally Posted by CDRIVE
Ok Trevor, I've re-written the code and this should work for you. In your Vb Graphics folder you should find a Bitmap named "Happy.bmp". It's a happy face. To put it into your PictureBox, go to the Properties window/Picture1 then scroll down to the Picture property. Click on the little button and navigate to Graphics/Assorted folder to find and select Happy.bmp. Then follow the comments in the code.
Let me know how it goes. It worked fine for me.
Code:
' From the Tool box: Put a Timer and a PictureBox on your Form.
' From the Properties window: Set the Form WindowStyle to (None) 0 and the form
' StartUpPosition to (Manual) 0.
Option Explicit
Private Sub Form_Load()
Picture1.BorderStyle = 0 'Set Picture1 Border to none.
Picture1.AutoSize = True 'AutoSize the Picture1 to the picture size
Picture1.Left = Me.Left 'Align left edge of Picture1 to left edge of Form
Picture1.Top = Me.Top 'Align top edge of Picture1 to top edge of Form
Me.Width = Picture1.Width 'Make Form width equal to Picture1 width
Me.Height = Picture1.Height 'Make Form height equal to Picture1 height
Timer1.Interval = 50
End Sub
Private Sub Timer1_Timer()
Static i% 'Create a counter
i% = i% + 10 'Add 10 to the count every 50mSec
Me.Left = i% 'Move Form left by the value of i% every 50mSec
Me.Top = i% 'Move Form down by the value of i% every 50mSec
End Sub
oh my god awesome!!!!!! how would i make that happen with say.... 15 images?
god dude you are so helpful, you spend all this time helping me and im just a newbie
also, how would i make it so a command button starts the image moving
and, when i run it, 1 out of every 5 sizes to the box correctly, like it shows the whole picture, then it shows a corner of it, then the blank form, then the blank form again a few times then the whole thing and repeats. whats up with that?
-
Re: pretty simple question hopefully
use imagelist to load your series of pics and then using one single picture box in the form to display random images from the imagelist, move the picture box as you wish using mr.cdrive's code on post #15.
-
Re: pretty simple question hopefully
Quote:
Originally Posted by trevor267
when i run it, 1 out of every 5 sizes to the box correctly, like it shows the whole picture, then it shows a corner of it, then the blank form, then the blank form again a few times then the whole thing and repeats. whats up with that?
Just wanted you to know that I read this but it's getting late and need to get to sleep. I'll try to get back to you over morning coffee. In the interim, did you follow all of the remarks regarding settings in the properties window? Make certain the Form StartUpPosition= Manual
-
Re: pretty simple question hopefully
Quote:
Originally Posted by sansknowledge
use imagelist to load your series of pics and then using one single picture box in the form to display random images from the imagelist, move the picture box as you wish using mr.cdrive's code on post #15.
As Sansknowledge suggested, the ImageList control can store all your images in your program, but I don't want to get into that until you get whatever bugs you have ironed out.
Back to your problem: Unlike My code in post 9 (which I edited since it was posted) the picture in post 15 is loaded into a PictureBox (Picture1) not on the Form as in post 9. So my question is this... Did you load the picture to the Form or the PictureBox? I have a suspicion that you have the picture on the Form instead of in the PictureBox.
-
Re: pretty simple question hopefully
Quote:
Originally Posted by CDRIVE
As Sansknowledge suggested, the ImageList control can store all your images in your program, but I don't want to get into that until you get whatever bugs you have ironed out.
Back to your problem: Unlike My code in post 9 (which I edited since it was posted) the picture in post 15 is loaded into a PictureBox (Picture1) not on the Form as in post 9. So my question is this... Did you load the picture to the Form or the PictureBox? I have a suspicion that you have the picture on the Form instead of in the PictureBox.
ahhhh got it, forgot to setthe start up to manual, thanks :)
edit, man this is so cool
EDIT: man your really getting me going, i figured out how to amke the picturebox invisible until you click the command button then that starts the moving, all i did was this to your code but it makes me feel good, also could you please explain the imagelist for me? thank you very much
Code:
Option Explicit
Private Sub Command1_Click()
Picture1.BorderStyle = 0 'Set Picture1 Border to none.
Picture1.AutoSize = True 'AutoSize the Picture1 to the picture size
Picture1.Left = Me.Left 'Align left edge of Picture1 to left edge of Form
Picture1.Top = Me.Top 'Align top edge of Picture1 to top edge of Form
Me.Width = Picture1.Width 'Make Form width equal to Picture1 width
Me.Height = Picture1.Height 'Make Form height equal to Picture1 height
Timer1.Interval = 50
Timer1.Enabled = True
Picture1.Visible = True
End Sub
Private Sub Timer1_Timer()
Static i% 'Create a counter
i% = i% + 10 'Add 10 to the count every 50mSec
Me.Left = i% 'Move Form left by the value of i% every 50mSec
Me.Top = i% 'Move Form down by the value of i% every 50mSec
End Sub
also added a textbox with a question and yes or no command buttons, both do the same thing so far.
also, how would i make it so a timer closes the thing after a certain amount of time
-
Re: pretty simple question hopefully
Quote:
Originally Posted by trevor267
ahhhh got it, forgot to setthe start up to manual, thanks :)
edit, man this is so cool
EDIT: man your really getting me going, i figured out how to amke the picturebox invisible until you click the command button then that starts the moving, all i did was this to your code but it makes me feel good, also could you please explain the imagelist for me? thank you very much
also added a textbox with a question and yes or no command buttons, both do the same thing so far.
also, how would i make it so a timer closes the thing after a certain amount of time
Glad to read that you took some initiative and you're having fun!
The ImageList control is part of the Microsoft Common Controls 6.0 collection that can be added to your Tool Box by clicking Project/Components/Microsoft Common Controls 6.0. It can be used to store multiple images within your compiled .exe. If you write a program that enables your users to add or remove images then it's not the way to go. In that case your images would usually be stored in the Dir or Folder that the app (App.Path) resides in.
You can disable the Timer in a number of ways. You can have a second Timer who,s Interval is set to what you want and put this in it's event procedure:
Code:
Private Sub Timer2_Timer()
Timer2.Interval= 20000 'Disable timer after 20Sec
Timer1.Enabled = False
End Sub
However, since you have a counter in the Timer1 event, you can do something like this:
Code:
If i% = 10000 Then
Timer1.Enabled = False
End If
Btw, it's probably a good idea to put this code in your Command1_Click event:
Code:
Command1.Visible = False
To see why, move your CommandButton to the upper left corner of your Form without adding this code.
-
Re: pretty simple question hopefully
Quote:
Originally Posted by CDRIVE
Glad to read that you took some initiative and you're having fun!
The ImageList control is part of the Microsoft Common Controls 6.0 collection that can be added to your Tool Box by clicking
Project/Components/Microsoft Common Controls 6.0. It can be used to store multiple images within your compiled .exe. If you write a program that enables your users to add or remove images then it's not the way to go. In that case your images would usually be stored in the Dir or Folder that the app
(App.Path) resides in.
You can disable the Timer in a number of ways. You can have a second Timer who,s Interval is set to what you want and put this in it's event procedure:
Code:
Private Sub Timer2_Timer()
Timer2.Interval= 20000 'Disable timer after 20Sec
Timer1.Enabled = False
End Sub
However, since you have a counter in the Timer1 event, you can do something like this:
Code:
If i% = 10000 Then
Timer1.Enabled = False
End If
Btw, it's probably a good idea to put this code in your Command1_Click event:
Code:
Command1.Visible = False
To see why, move your CommandButton to the upper left corner of your Form
without adding this code.
i made it not visible, also i got the timer thing so i like it :D
-
Re: pretty simple question hopefully
Quote:
Originally Posted by trevor267
i made it not visible, also i got the timer thing so i like it :D
Trevor, add another timer to your form and add this to the Form_Load event.
Code:
Timer2.Interval = 1
Timer2.Enabled = False ' Change this to False to see what happens
Then put this in a blank area of the code window.
Code:
Private Sub Timer2_Timer()
Static i%
If i% < 11600 Then
i% = i% + 20
Me.Left = 15000 - i%
Me.Top = 0 + i%
Debug.Print i%
End If
If i% > 11500 Then
Timer2.Enabled = False
Timer1.Enabled = True
i% = 0
End If
End Sub
BTW, before you get chastised by the moderators please truncate your text and code quotes. ;)
-
Re: pretty simple question hopefully
Quote:
BTW, before you get chastised by the moderators please truncate your text and code quotes. ;)
truncate?
also, ive already got a timer that closes it when it gets to the end, thats what i tried to say in my last post, not i just need it so more than 1 picture opens up
-
Re: pretty simple question hopefully
Quote:
Originally Posted by trevor267
truncate?
also, ive already got a timer that closes it when it gets to the end, thats what i tried to say in my last post, not i just need it so more than 1 picture opens up
That's not what Timer2 does in the last code I posted. Did you run it?
To get more than one image moving around the screen it would look best if you use multiple Forms with PicBoxes on each. Then you will want to play with the Timer code that governs the positions of the Forms.
As far as truncating is concerned, you did it in your last quote.:thumb: