|
-
Mar 26th, 2002, 12:04 AM
#1
Thread Starter
Member
how to use code to add a picture box to the form
i have a frame contorl on my form, i want to use code to add a picture box in the frame, and can set the position of the picture box too.please help.
_______________________
VB 6 professional
java2 SDK 1.3
-
Mar 26th, 2002, 12:39 AM
#2
-= B u g S l a y e r =-
VB Code:
Private Sub Command1_Click()
Dim ctlPB As Control
Set ctlPB = Controls.Add("VB.PictureBox", "PB1ox", Frame1)
ctlPB.Top = 160
ctlPB.Left = 60
ctlPB.Height = Frame1.Height - 220
ctlPB.Width = Frame1.Width - 200
ctlPB.Visible = True
End Sub
-
Mar 26th, 2002, 12:52 AM
#3
Frenzied Member
Try This
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Sub Form_Load()
Dim x As Control
Set x = Controls.Add("VB.PictureBox", "Pic1", Frame1)
x.Visible = True
SetParent x.hWnd, Frame1.hWnd
End Sub
-
Mar 26th, 2002, 01:21 AM
#4
Thread Starter
Member
can you give me some explaination?
thank you very much for you guys help,since i am not good at windows API , so i prefer the method which peet wrote.
hi Peet:
i hope you can give me some explaination,
Set ctlPB = Controls.Add("VB.PictureBox", "PB1ox", Frame1)
in this stament what is "PB1ox" mean?
and in
ctlPB.Height = Frame1.Height - 220
ctlPB.Width = Frame1.Width - 200
why height and width need to minus 220 and 200?
thanks
_______________________
VB 6 professional
java2 SDK 1.3
-
Mar 26th, 2002, 01:54 AM
#5
-= B u g S l a y e r =-
VB Code:
Private Sub Command1_Click()
Dim ctlPB As Control
'"VB.PictureBox" = the type of control I want to add
'"PictureBox1" = the name of the control (I changed it :) )
'Frame1 = the container that I want the picture box placed in
Set ctlPB = Controls.Add("VB.PictureBox", "PictureBox1", Frame1)
'place the picture box inside the Frame1, so that it does not
'cover the frame...
ctlPB.Top = 160
ctlPB.Left = 60
ctlPB.Height = Frame1.Height - 220
ctlPB.Width = Frame1.Width - 200
'show the picturebox
ctlPB.Visible = True
End Sub
-
Mar 26th, 2002, 01:56 AM
#6
-= B u g S l a y e r =-
Re: can you give me some explaination?
Originally posted by bamboosam
....
ctlPB.Height = Frame1.Height - 220
ctlPB.Width = Frame1.Width - 200
why height and width need to minus 220 and 200?
thanks
doesnt have to minus those numbers, but if u want the picturebox not to overlap the frame that its in, u will have to do this.
-
Mar 26th, 2002, 02:44 AM
#7
Thread Starter
Member
thanks for your explaination,now i understand very clearly.
but now i have another problem
i add this stamemt to the program " PictureBox1.Print ("hello") ", but it did not work
Private Sub Command1_Click()
Dim ctlPB As Control
Set ctlPB = Controls.Add("VB.PictureBox", "PictureBox1", Frame1)
ctlPB.Top = 160
ctlPB.Left = 60
ctlPB.Height = 500
ctlPB.Width = 500
ctlPB.Visible = True
PictureBox1.Print ("hello")
End Sub
by the way, i also want to draw lines in the frame, and also need to set the position of the line, can u tell me how to do?
thank you very much
_______________________
VB 6 professional
java2 SDK 1.3
-
Mar 26th, 2002, 02:52 AM
#8
-= B u g S l a y e r =-
VB Code:
Option Explicit
Private ctlPB As Control
Private Sub Command1_Click()
'"VB.PictureBox" = the type of control I want to add
'"PictureBox1" = the name of the control (I changed it :) )
'Frame1 = the container that I want the picture box placed in
Set ctlPB = Controls.Add("VB.PictureBox", "PictureBox1", Frame1)
'place the picture box inside the Frame1, so that it does not
'cover the frame...
ctlPB.Top = 160
ctlPB.Left = 60
ctlPB.Height = Frame1.Height - 220
ctlPB.Width = Frame1.Width - 200
'show the picturebox
ctlPB.Visible = True
End Sub
Private Sub Command2_Click()
ctlPB.Print "Hello"
End Sub
-
Mar 26th, 2002, 02:58 AM
#9
Frenzied Member
SEt the control's AutoRedraw Property to True
ctlPB.AutoRedraw = True
-
Mar 26th, 2002, 03:00 AM
#10
-= B u g S l a y e r =-
make a line in the frame from one corner to another
VB Code:
Private Sub Command3_Click()
Dim ctlLine1 As Control
Set ctlLine1 = Controls.Add("VB.Line", "Line1", Frame1)
ctlLine1.Visible = True
ctlLine1.X1 = 0
ctlLine1.X2 = Frame1.Width
ctlLine1.Y1 = 0
ctlLine1.Y2 = Frame1.Height
End Sub
-
Mar 29th, 2002, 11:57 PM
#11
Thread Starter
Member
hi peet:
now i got another problem,now i want to remove all the controls
which in the frame, but i can not find a way to do it,please help,thanks alot.
_______________________
VB 6 professional
java2 SDK 1.3
-
Mar 29th, 2002, 11:59 PM
#12
VB Code:
Dim c As Control
For Each c In Controls
If c.Container Is Frame1
Controls.Remove c
End If
Next
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Mar 30th, 2002, 12:24 AM
#13
The picture isn't missing
instead of using the SetParent API you can just use
set something.Container = Frame1
Remember, if someone's post was not helpful, you can always rate their post negatively  .
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
|