Option Explicit Private Declare Function SetPixel Lib "gdi32" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long, ByVal Color As Long) As Long Private Sub Drawline(X1 As Single, Y1 As Single, X2 As Single, Y2 As Single) 'Temporary variables for loop count Dim A As Single Dim B As Single ' Temporary variable, for swapping Dim temp As Single ' X2 must be greater than X1 If X1 > X2 Then temp = X1 X1 = X2 X2 = temp End If ' Y2 must be greater than Y1 If Y1 > Y2 Then temp = Y1 Y1 = Y2 Y2 = temp End If 'Two deltas for computing the Slope Dim DeltaX As Single Dim DeltaY As Single 'The slope itself, used for determining the line direction Dim Slope As Single 'Two variables, for drawing the line 'Note: it's easy to change the code, so you'll get a matrix of pixels Dim CurrX As Single Dim CurrY As Single DeltaX = X2 - X1 DeltaY = Y2 - Y1 'Allready fixed, but a good habbit to make deltas value absolute DeltaX = Abs(DeltaX) DeltaY = Abs(DeltaY) 'Two boolean variables for determining the line type Dim isVertical As Boolean Dim isHorizonal As Boolean 'Checks if the line is vertical or horizonal, or both, in this case see next quote If DeltaY = 0 Then isHorizonal = True If DeltaX = 0 Then isVertical = True 'In case that that the pixels are in the same place, draw one pixel If isVertical And isHorizonal Then 'You may replace the setpixel command with any pixel drawing procedure, It won't affect the outcome SetPixel picMain.hDC, X1, X2, RGB(255, 0, 0) Exit Sub End If 'In case that the pixel is not horizonal and not vertical, draw using slope If Not isVertical And Not isHorizonal Then 'These three features are built to give the best slopes check: If DeltaY > DeltaX Then Slope = DeltaY / DeltaX CurrY = Y1 For CurrX = X1 To X2 'Draws the pixels that build the line SetPixel picMain.hDC, CurrX, CurrY, RGB(255, 0, 0) CurrY = CurrY + Slope Next CurrX Exit Sub End If If DeltaX > DeltaY Then Slope = DeltaX / DeltaY CurrX = X1 For CurrY = Y1 To Y2 'Draws the pixels that build the line SetPixel picMain.hDC, CurrX, CurrY, RGB(255, 0, 0) CurrX = CurrX + Slope Next CurrY Exit Sub End If 'This one in case DeltaX = DeltaY, changing one of the deltas, and going back to to check If DeltaX = DeltaY Then DeltaX = DeltaX + 1 GoTo check End If End If 'In case that the line is vertical, always use the same X, and with Y ahead If isVertical Then CurrX = X1 For CurrY = Y1 To Y2 SetPixel picMain.hDC, CurrX, CurrY, RGB(255, 0, 0) Next CurrY End If 'In case that the line is horizonal, always use the same Y, and with X ahead If isHorizonal Then CurrY = Y1 For CurrX = X1 To X2 SetPixel picMain.hDC, CurrX, CurrY, RGB(255, 0, 0) Next CurrX End If End Sub Private Sub cmdDraw_Click() Drawline InputBox("X1"), InputBox("Y1"), InputBox("X2"), InputBox("Y1") picMain.Refresh End Sub Private Sub picMain_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single) lblX = x lblY = y End Sub scalemode 1pouce = 1440 twips 1cm = 567 twips Private Sub mnuFileOpen_Click() OpenDocument 'Call OpenDocument function End Sub