468,514 Members | 1,588 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,514 developers. It's quick & easy.

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.CommandButton cmdNest
Caption = "align "
Height = 375
Left = 6000
TabIndex = 2
Top = 6840
Width = 1815
End
Begin VB.CommandButton 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_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = 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).Container = PicTable
imgDarfa(0).Left = 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).Container = Me
imgDarfa(i).Width = Wd
imgDarfa(i).Height = 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).Visible = True
imgDarfa(i).Caption = 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).Left = imgDarfa(i - 1).Left + imgDarfa(i - 1).Width
imgDarfa(i).Top = 5
Else
imgDarfa(i).Left = 5
imgDarfa(i).Top = 5
End If
Next i

End Sub
Mar 31 '08 #1
0 1055

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by Chris | last post: by
9 posts views Thread by Veerle | last post: by
3 posts views Thread by cai_rongxi | last post: by
reply views Thread by Fir5tSight | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.