-
I have a program that makes creates a shape from a set of coordinates in a textbox, but i want it to put the shape as a part of a picture box instead of the form. Is this possible?
Here is the code i have so far:
Code:
Public WithEvents myshape As Shape
Private Sub Create_Shape()
MyCoords = Split(Text11.Text, ",")
Set myshape = Controls.Add("VB.Shape", "abc")
myshape.left = MyCoords(0)
myshape.top = MyCoords(1)
myshape.width = MyCoords(2)
myshape.height = MyCoords(3)
myshape.Shape = 0
myshape.BorderColor = &HFF00FF
myshape.BorderWidth = 3
myshape.Visible = True
End Sub
[Edited by sp007 on 11-29-2000 at 09:54 PM]
-
You could always draw them directly using the API, but I'm not sure if that is what you want. If it is let me know and I'll send some code.
-
I suppose that could work. Would you still be able to set the properties, such as borderwidth as bordercolor through api?
-
When drawing to a device such as a PictureBox the borderwidth and bordercolor are determined by the current properties of the surface you are drawing too, in this case the PictureBox, here is a quick example of how to draw a Rectangle.
Code:
Private Declare Function Rectangle Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Sub Picture1_Paint() ' all drawing should be done in paint event
Dim lRet As Long ' return value from drawing function
Picture1.DrawWidth = 2 ' same as borderwidth
Picture1.ForeColor = RGB(255, 0, 0) ' same as bordercolor
'draw rectangle
lRet = Rectangle(Picture1.hdc, 5, 5, 50, 100)
End Sub
Also the api uses Pixels as coordinates rather than Twips so if you wanted to convert a Twip coordinate to a Pixel coordinate use this formula.
Code:
x = x / Screen.TwipsPerPixelX
-
Excellent. Thanks a ton. It works Great:)