I want help How I can align rectangles

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rafeig77
    New Member
    • Mar 2008
    • 1

    #1

    I want help How I can align rectangles

    I want help
    How I can align rectangles differ in its tow dimensions inside big rectangle with lesser waste in area ?

    for mor information
    align.rar - 1.8 Kb

    or:
    copy this code to text file and change its extension from txt to frm and insert this form to new project:

    VERSION 5.00
    Begin VB.Form frmMain
    Caption = "Form1"
    ClientHeight = 7485
    ClientLeft = 60
    ClientTop = 450
    ClientWidth = 8100
    LinkTopic = "Form1"
    ScaleHeight = 499
    ScaleMode = 3 'Pixel
    ScaleWidth = 540
    StartUpPosition = 3 'Windows Default
    Begin VB.CommandButto n cmdNest
    Caption = "align "
    Height = 375
    Left = 6000
    TabIndex = 2
    Top = 6840
    Width = 1815
    End
    Begin VB.CommandButto n cmdNew
    Caption = "new"
    Height = 375
    Left = 6000
    TabIndex = 1
    Top = 6240
    Width = 1815
    End
    Begin VB.PictureBox PicTable
    Appearance = 0 'Flat
    BackColor = &H80000005&
    ForeColor = &H80000008&
    Height = 3660
    Left = 6000
    ScaleHeight = 242
    ScaleMode = 3 'Pixel
    ScaleWidth = 120
    TabIndex = 0
    Top = 2280
    Width = 1830
    End
    Begin VB.Label imgDarfa
    Alignment = 2 'Center
    Appearance = 0 'Flat
    BackColor = &H80000018&
    BorderStyle = 1 'Fixed Single
    Caption = "1"
    BeginProperty Font
    Name = "MS Sans Serif"
    Size = 13.5
    Charset = 178
    Weight = 700
    Underline = 0 'False
    Italic = 0 'False
    Strikethrough = 0 'False
    EndProperty
    ForeColor = &H000040C0&
    Height = 900
    Index = 0
    Left = 840
    TabIndex = 3
    Top = 1800
    Width = 450
    End
    End
    Attribute VB_Name = "frmMain"
    Attribute VB_GlobalNameSp ace = False
    Attribute VB_Creatable = False
    Attribute VB_PredeclaredI d = True
    Attribute VB_Exposed = False
    Option Explicit
    '
    Dim numDarfa As Integer

    Private Sub cmdNest_Click()
    'How I can align this rectangles (imgDarfa) in the big rectangle (PicTable)
    Set imgDarfa(0).Con tainer = PicTable
    imgDarfa(0).Lef t = 0
    imgDarfa(0).Top = 0
    End Sub

    Private Sub cmdNew_Click()
    Dim i As Integer
    Dim m As Integer
    Dim Wd As Single
    Dim Ht As Single
    Dim D As Single
    Dim n As Integer
    '
    For i = 0 To numDarfa
    m = Rnd * 100
    If m < 50 Then m = 1 Else m = -1
    D = Rnd * 30
    Ht = 60 + m * D

    m = Rnd * 100
    If m < 50 Then m = 1 Else m = -1
    D = Rnd * 15
    Wd = 30 + m * D

    Set imgDarfa(i).Con tainer = Me
    imgDarfa(i).Wid th = Wd
    imgDarfa(i).Hei ght = Ht

    '

    Next i
    ReArrange
    End Sub

    Private Sub Form_Load()
    Dim i As Integer
    '
    numDarfa = 14
    Randomize Timer
    For i = 1 To numDarfa
    Load imgDarfa(i)
    imgDarfa(i).Vis ible = True
    imgDarfa(i).Cap tion = i + 1
    Next i
    cmdNew_Click
    End Sub
    '





    Private Sub ReArrange()
    Dim i As Integer
    For i = 0 To imgDarfa.UBound
    If i <> 0 Then
    imgDarfa(i).Lef t = imgDarfa(i - 1).Left + imgDarfa(i - 1).Width
    imgDarfa(i).Top = 5
    Else
    imgDarfa(i).Lef t = 5
    imgDarfa(i).Top = 5
    End If
    Next i

    End Sub
Working...