Bart644
Jun 8th, 2001, 12:25 AM
Hello everyone, I am a custom kitchen cabinet maker by trade and visual basic
is a new found hobby of mine. I am trying to write a program to draw simple floor
plans to help me with my kitchen layouts.
Well I'm off to a great start!
I can't draw a rectangle on an angle. However, I can draw a rectangle using
using the top and left property of the shape control. But that don't tilt.
Could someone show me the code to draw a rectangle that tilts on
a angle. A constant of 4 could represent the wall thickness.
I would like to be able to draw the rectangle with the line control and then
transfer those x,y to use the line method in a picture box at any angle that I want
using the mouse.
I would like to use a label to show the angle in degrees ( 0 - 360 ) that the
rectangle is being drawn.
I know how to use the line method to draw one line ( or side ) on an angle,
but I don’t know the formula to draw the other three sides and keep
all the corners square.
I would like to thank everyone who has taken the time to look at this
this, and especially grateful to anyone who can help with the code.
Here is what I have:
Form name = Form1
StartUpPosition = Manual
ScaleMode = 1
Width = 7980
Height = 7560
Picture box name = Picture1
Appearance = 1-3D
BackColor = White
AutoRedraw = True
MousePointer = 2-Cross
Hieght = 5535
Left = 120
Top = 120
Width = 7215
ScaleMode = 3-Pixel
Line control named = Line1 ‘ Used for rubber banding effect
BorderColor = Red
Visable = False
X1 = 120
X2 = 224
Y1 = 312
Y2 = 312
'*******************************************
Declarations
Dim a As Long
Dim b As Long
Dim c As Long
Dim d As Long
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
a = X
b = Y
c = X
d = Y
Line1.X1 = a
Line1.Y1 = b
Line1.X2 = c
Line1.Y2 = d
Line1.Visible = True
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
c = X
d = Y
Line1.X2 = c
Line1.Y2 = d
'Label1.Caption = "Some sort of code to show the angle of the rectangle" & "Degrees"
End Sub
Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim e As Long
Dim f As Long
Dim g As Long
Dim h As Long
e = Line1.X1
f = Line1.Y1
g = Line1.X2
h = Line1.Y2
Picture1.Line (e, f)-(g, h), RGB(50, 75, 255)
Line1.X1 = 0
Line1.Y1 = 0
Line1.X2 = 0
Line1.Y2 = 0
Line1.Visible = False
Picture1.Visible = False
Picture1.Visible = True
'*************************************************
'All this extra code will draw a square on any angle, but not the rectangle
'that I want to use
Dim X1 As Long
Dim X2 As Long
Dim Y1 As Long
Dim Y2 As Long
Dim SlopeT As Long 'Top part of slope fraction
Dim SlopeB As Long 'Bottom part of slope fraction
SlopeT = (h - f) * 1
SlopeB = (g - e) * -1
X1 = e + SlopeT
Y1 = f + SlopeB
Picture1.Line (e + SlopeT, f + SlopeB)-(e, f), RGB(50, 75, 255)
'the other side
SlopeT = (f - h) * -1
SlopeB = (e - g) * 1
X2 = g + SlopeT
Y2 = h + SlopeB
Picture1.Line (g + SlopeT, h + SlopeB)-(g, h), RGB(50, 75, 255)
'And the last line
Picture1.Line (X1, Y1)-(X2, Y2), RGB(50, 75, 255)
End Sub
is a new found hobby of mine. I am trying to write a program to draw simple floor
plans to help me with my kitchen layouts.
Well I'm off to a great start!
I can't draw a rectangle on an angle. However, I can draw a rectangle using
using the top and left property of the shape control. But that don't tilt.
Could someone show me the code to draw a rectangle that tilts on
a angle. A constant of 4 could represent the wall thickness.
I would like to be able to draw the rectangle with the line control and then
transfer those x,y to use the line method in a picture box at any angle that I want
using the mouse.
I would like to use a label to show the angle in degrees ( 0 - 360 ) that the
rectangle is being drawn.
I know how to use the line method to draw one line ( or side ) on an angle,
but I don’t know the formula to draw the other three sides and keep
all the corners square.
I would like to thank everyone who has taken the time to look at this
this, and especially grateful to anyone who can help with the code.
Here is what I have:
Form name = Form1
StartUpPosition = Manual
ScaleMode = 1
Width = 7980
Height = 7560
Picture box name = Picture1
Appearance = 1-3D
BackColor = White
AutoRedraw = True
MousePointer = 2-Cross
Hieght = 5535
Left = 120
Top = 120
Width = 7215
ScaleMode = 3-Pixel
Line control named = Line1 ‘ Used for rubber banding effect
BorderColor = Red
Visable = False
X1 = 120
X2 = 224
Y1 = 312
Y2 = 312
'*******************************************
Declarations
Dim a As Long
Dim b As Long
Dim c As Long
Dim d As Long
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
a = X
b = Y
c = X
d = Y
Line1.X1 = a
Line1.Y1 = b
Line1.X2 = c
Line1.Y2 = d
Line1.Visible = True
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
c = X
d = Y
Line1.X2 = c
Line1.Y2 = d
'Label1.Caption = "Some sort of code to show the angle of the rectangle" & "Degrees"
End Sub
Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim e As Long
Dim f As Long
Dim g As Long
Dim h As Long
e = Line1.X1
f = Line1.Y1
g = Line1.X2
h = Line1.Y2
Picture1.Line (e, f)-(g, h), RGB(50, 75, 255)
Line1.X1 = 0
Line1.Y1 = 0
Line1.X2 = 0
Line1.Y2 = 0
Line1.Visible = False
Picture1.Visible = False
Picture1.Visible = True
'*************************************************
'All this extra code will draw a square on any angle, but not the rectangle
'that I want to use
Dim X1 As Long
Dim X2 As Long
Dim Y1 As Long
Dim Y2 As Long
Dim SlopeT As Long 'Top part of slope fraction
Dim SlopeB As Long 'Bottom part of slope fraction
SlopeT = (h - f) * 1
SlopeB = (g - e) * -1
X1 = e + SlopeT
Y1 = f + SlopeB
Picture1.Line (e + SlopeT, f + SlopeB)-(e, f), RGB(50, 75, 255)
'the other side
SlopeT = (f - h) * -1
SlopeB = (e - g) * 1
X2 = g + SlopeT
Y2 = h + SlopeB
Picture1.Line (g + SlopeT, h + SlopeB)-(g, h), RGB(50, 75, 255)
'And the last line
Picture1.Line (X1, Y1)-(X2, Y2), RGB(50, 75, 255)
End Sub