怎样 可以 固定大的容器 不重叠 排列
如固定大的容器 (3000*500) 像数中
有N个文件框 text1(N)
top 值是知道,不可以改变,随机给的
Height 值是知道,不可以改变,随机给的Width,Left 可随意变,top值 相同的 文件框 Width 放大缩小 ,要平均如:(text1(1) 至text1(3)) 的top值 相同的 text1(1) 至text1(3)的Width 必须等于容器宽的 三分一(500*1/3),因为有三个并列,每一个并列文件框 Width 就等于 容器 的三分一
可以 用 left 值 左右 变动, 不让 重叠,如果并列相同top值文本框太多,Width 缩小
请问 这样的源码 怎样 写 ,给你 200 分
如固定大的容器 (3000*500) 像数中
有N个文件框 text1(N)
top 值是知道,不可以改变,随机给的
Height 值是知道,不可以改变,随机给的Width,Left 可随意变,top值 相同的 文件框 Width 放大缩小 ,要平均如:(text1(1) 至text1(3)) 的top值 相同的 text1(1) 至text1(3)的Width 必须等于容器宽的 三分一(500*1/3),因为有三个并列,每一个并列文件框 Width 就等于 容器 的三分一
可以 用 left 值 左右 变动, 不让 重叠,如果并列相同top值文本框太多,Width 缩小
请问 这样的源码 怎样 写 ,给你 200 分
解决方案 »
- 谁用过adam模块的modbus通信!
- 摄像头取像问题(从摄像头取像到内存,再从内存里取像到界面)高分求教!!!!!!!!
- 动态生成了若干个窗体,如何分辨和控制每个窗体中的控件?
- VB以前能用的程序数据库重新导入之后就不能用了
- 怎样清除listbox里面重复的项
- 既然vb不支持继承,那么当两个窗体的代码雷同的情况下, 启不是会造成代码的极大冗余,而且代码的可复用性也很差??
- Visual Basic 速学系统 V16.0.865 成功发布
- vb如何写入、读取INI文件
- setup factory有没有中文版,最新版本(支持VB6中文版)是多少
- 如何用VB解方程,求大神帮忙,谢谢谢谢谢谢谢谢!!!
- 大家有什么好的建议?
- 传回窗体事件
使用2个指针i.j,开始为1,
while i<=nif text(I).top=text(I+1).top then i=i+1else lngWidth=你的控件的WIDTH/(i-j+1)
text(j).left=0
text(j).width=lngWidth
j=j+1 while j<i
text(j).width=lngWidth
text(j).left=text(j-1).left+lngWidth
j=j+1
wend
i=i+1
end ifwend
while i<=nif text(DAT(I)).top=text(DAT(I+1)).top then i=i+1else lngWidth=你的控件的WIDTH/(i-j+1)
text(DAT(j)).left=0
text(DAT(j)).width=lngWidth
j=j+1 while j<i
text(DAT(j)).width=lngWidth
text(DAT(j)).left=text(DAT(j-1)).left+lngWidth
j=j+1
wend
i=i+1
end ifwend
text(j).left=0
text(j).width=lngWidth
j=j+1 while j<i
text(j).width=lngWidth
text(j).left=text(j-1).left+lngWidth
j=j+1
wend
i=i+1
end ifwend==================
简单来说 我这个可算是一个 二维装箱 算法
不同的就是, top 值是知道,不可以改变,高度不可以变动,就是说 上下 位置 是不可以变动
Height 值是知道,不可以改变, 长度 都不可变Width,Left 可随意变,Width --> 可以 把这个 缩小,保证 不超出 容器的,不可以太小,最好平均,(如:当前列的,1/N)
Left--> 可以左右 移动,来保证,不重叠
大循环外面需要判断
IF J<I then然后把上面ELSE后的照搬。
dim top(5) as integer 'top 值是已知的
dim i as integer, n as integer, m as integertop(0) = 100
...for i = 0 to 5
n = 0
m = 0
for each tx in me.controls
if tx.top = top(i) then n = n + 1
next
for each tx in me.controls
if tx.top = top(i) then
tx.width = tx.container.width \ n
tx.left = tx.width * m
m = m + 1
end if
next
next i
不行,重叠呢
Private Sub Form_Click()
Dim tx As TextBox
Dim top(5) As Integer 'top 值是已知的
Dim i As Integer, n As Integer, m As Integer
top(0) = Text1(0).top
top(1) = Text1(1).top
top(2) = Text1(2).top
top(3) = Text1(3).top
top(4) = Text1(4).top
top(5) = Text1(5).top
For i = 0 To 5
n = 0
m = 0
For Each tx In Me.Controls
If tx.top = top(i) Then n = n + 1
Next
For Each tx In Me.Controls
If tx.top = top(i) Then
tx.Width = tx.Container.Width \ n
tx.Left = tx.Width * m
m = m + 1
End If
Next
Next i
End Sub
'为简单起见假设有两种TOP(100,200),动态的TEXT1有5个(1到5)
'FORM的SCALEMODE为PIXEL'数组存储TEXT1的索引,为简单化其内容为已经排好序的
Dim dat(1 To 5) As LongPrivate Sub Command1_Click()
'针对排序的数组DAT来均匀分布TEXT
Dim i As Long, j As Long, lngWidth As Long
i = 1
j = 1While i < UBound(dat)
If Text1(dat(i)).Top = Text1(dat(i + 1)).Top Then
i = i + 1
Else
lngWidth = Form1.ScaleWidth / (i - j + 1)
Text1(j).Left = 0
Text1(j).Width = lngWidth
j = j + 1
While j <= i
Text1(j).Left = Text1(j - 1).Left + lngWidth
Text1(j).Width = lngWidth
j = j + 1
Wend
i = i + 1
End IfWendIf j <= i Then
lngWidth = Form1.ScaleWidth / (i - j + 1)
Text1(j).Left = 0
Text1(j).Width = lngWidth
j = j + 1
While j <= i
Text1(j).Left = Text1(j - 1).Left + lngWidth
Text1(j).Width = lngWidth
j = j + 1
Wend
End If
End SubPrivate Sub Form_Load()
Dim i As Long
For i = 2 To 5
Load Text1(i)
Text1(i).Visible = True
Next
'下列代码是为了简化目的,实际应用中TEXT1的下标可以是无规律的,但DAT的元素必须排序
Text1(1).Top = 100
Text1(2).Top = 100
Text1(3).Top = 100
Text1(4).Top = 200
Text1(5).Top = 200
dat(1) = 1
dat(2) = 2
dat(3) = 3
dat(4) = 4
dat(5) = 5End SubPrivate Sub Form_Unload(Cancel As Integer)
Dim i As LongFor i = 2 To UBound(dat)
Unload Text1(i)
Next
End Sub
============================
再次谢谢,对不起,昨晚因为 网速太慢 ,打不开现在才可以看到,
=====================================================
就以下面这个来说Text1(1).Top = 100
Text1(2).Top = 100
Text1(3).Top = 100
Text1(4).Top = 200
Text1(5).Top = 200
=====================================================
几个文本框,真的 做到 Width 值平均容器,但漏了重要一点,
就重叠Text1(1到3)与下一行的Text1(4到5)重叠一开始就说明,不可以重叠,平均分配到容器,只是为了美观,这个不是重要,最重要就是,不重叠重叠这里 要首要考虑,所以它们的 Height 考虑,每一个文本框的Height,都有可能不同,如:
第一行
Text1(1).Top = 100 Text1(1).Height = 100
Text1(2).Top = 100 Text1(2).Height = 600 --->明显这个,Text1(2).Height 夸越了第二行
Text1(3).Top = 100 Text1(3).Height= 100
第二行Text1(4).Top = 200 Text1(4).Height= 400
Text1(5).Top = 200 Text1(5).Height= 400
======================================================
上面分析,
第一行就有三列,为美观,当然要最好做到,每个文本框的Width ,是平均,分配为三分一.之后到 第二行第二行,表明看上,只有两列,但实际是,要按三列划分,因为第一行的 Text1(2)的Height夸越到了第二行中,要考虑第二行不与夸越过来的第一行的第二列文本框[Text1(2)]重叠一起,所以必须要把第二行文本框Left与Width 发生变化,第二行Left值左右移动或者Width值缩小来保证不重叠.注意一点就是
容器空间有限,要合理分配,不可以只把 Left值移动,而不缩小Width值
================================那最终的 目的 (假定 容器的Width 为 900 )第一行
Text1(1).Top = 100
Text1(1).Height = 100
Text1(1).Left=0
Text1(1).Width= 300 --->(三分一)
==================================
Text1(2).Top = 100
Text1(2).Height = 600 --->明显这个,Text1(2).Height 夸越了第二行
Text1(2).Left=300 -->Text1(1).Left + Text1(1).Width
Text1(2).Width= 300 --->(三分一)
=======================================
Text1(3).Top = 100
Text1(3).Height= 100
Text1(3).Left=600 -->Text1(2).Left + Text1(2).Width
Text1(3).Width= 300 --->(三分一)
************************************
第二行Text1(4).Top = 200
Text1(4).Height= 400
Text1(4).Left=0 --->(第一行第一列没有夸越,就是说有空间,可以为0)
Text1(4).Width= 300 --->(三分一)
====================================================
Text1(5).Top = 200
Text1(5).Height= 400
Text1(5).Left=600 ---->[这个应该为600,要考虑,第一行第二列的夸越,就是难点]
Text1(5).Width= 300 --->(三分一)
**********************************************
提示:
如果 第一行Text1(1)及Text1(2)的Height都夸越到第二行或第三行,更多行,那第二行Width变了四分一了,第一行Text1(1)及Text1(2)的Width,都为四分一,而Text1(3),为三分一=======================
这里说出我的想法,当然,只是个人,不一定是正确,最小,我都不会,要不,我都不用浪费200分,现在的可用分,来之不易,不像以前那样,不答问题每周都有分送.
===========================
首先把行数定下来, 因为,不同的 TOP,就代表一行
根据,每一个文本框TOP与Height,定下夸越过那行,来确定每行有多少列
接着,有了列数,之后,根据每行的列数,得出文本框的Width值最后,就是Left,这个就是难点,合理分配空间,而又保不重叠!
TEXT 只是 我方便列出问题的一个对像,真的的对像 当然不是这个啦!用手工 当然什么都可以啦,不可能这样做呢?
Private Function Sort(ByVal N As Long, TextList As Object)
Dim curWidth As Long
curWidth = 1000
Dim used() As Boolean
ReDim used(N) As Boolean
For i = 0 To N - 1
used(i) = False
TextList(i).Left = 0
TextList(i).Width = curWidth
Next i
Dim numUsed As Long
numUsed = 0
Dim curTop As Long
curTop = 0
Dim curLeft As Long
curLeft = 0
Dim found As Boolean
Do While numUsed < N
found = False
For i = 0 To N - 1
If Not used(i) And TextList(i).Top >= curTop Then
found = True
used(i) = True
TextList(i).Left = curLeft
TextList(i).Width = curWidth
curTop = TextList(i).Top + TextList(i).Height
numUsed = numUsed + 1
Exit For
End If
Next i
If Not found Then
curTop = 0
curLeft = curLeft + curWidth
End If
Loop
End Function