根据仪表大小动态生成形状
这里主要说说教室状态卡片里的教室如何动态生成。在点击1号楼、2号楼、3号楼的时候,分别显示不同楼的房间数,并可以根据窗口大小适应。
前面的定位帮助里有说到,线性仪表的宽和高是通过AxisLength和BaseFactor指定的,所以我们只需要使用仪表控件的宽和高乘于这2个属性就可以得到仪表的宽和高。
到仪表控件的ItemClick添加以下代码:
-
-
If TypeOf e.Item Is c1.Win.C1Gauge.C1GaugeBaseShape AndAlso e.Item.name.endswith("号楼") Then
-
Dim gg As LinearGauge = e.Gauge
-
gg.CoverShapes.Clear
-
Dim cm As GaugeColorMap = gg.ColorMaps(0)
-
-
Dim rg As GaugeRectangle
-
Dim cap As GaugeCaption
-
Dim cnt As Integer = Rand.Next(20, 40)
-
Dim cw As Integer = e.Sender.Width * 0.4 - 30
-
Dim ch As Integer = e.Sender.Height * 0.45 * 0.6
-
Dim k As Integer = Math.Ceiling(cnt ^ 0.5)
-
Dim w As Integer = Math.Floor(cw / k) - 15
-
Dim h As Integer = Math.Floor(ch / k) - 15
-
Dim x As Integer = 0
-
Dim y As Integer = 0
-
Output.Show("Cilck: cw=" & cw & ", ch=" & ch)
-
For i As Integer = 0 To cnt - 1
-
If x = k Then
-
x = 0
-
y += 1
-
End If
-
rg = New GaugeRectangle
-
rg.Viewport.Width = w
-
rg.Viewport.Height = h
-
rg.Viewport.X = 20 + x * (15 + w)
-
rg.Viewport.Y = 65 + y * (15 + h)
-
rg.Filling.Color = cm.ValueColors(rand.Next(0, 3)).Color
-
gg.CoverShapes.Add(rg)
-
-
cap = New GaugeCaption
-
cap.Viewport.Width = w
-
cap.Viewport.Height = h
-
cap.Viewport.X = 20 + x * (15 + w)
-
cap.Viewport.Y = 65 + y * (15 + h)
-
cap.Text = e.Item.name.replace("号楼", "") & Format(i + 1, "00")
-
cap.Color = Color.White
-
gg.CoverShapes.Add(cap)
-
x += 1
-
Next
-
End If
如果需要仪表控件大小发生变化后,房间的大小也一起变化,到窗口SizeChanged添加以下代码:
-
Dim g As WinForm.Gauges = e.Form.Controls("Guages1")
-
Dim lg As LinearGauge = g.Gauges(0)
-
Dim cnt As Integer = lg.CoverShapes.Count
-
Dim cw As Integer = g.Width * 0.4 - 30
-
Dim ch As Integer = g.Height * 0.45 * 0.6
-
-
Dim k As Integer = Math.Ceiling((cnt / 2) ^ 0.5)
-
Dim w As Integer = Math.Floor(cw / k) - 15
-
Dim h As Integer = Math.Floor(ch / k) - 15
-
Dim x As Integer = 0
-
Dim y As Integer = 0
-
-
Dim sh As C1.Win.C1Gauge.C1GaugeBaseShape
-
For i As Integer = 0 To cnt - 1 Step 2
-
If x = k Then
-
x = 0
-
y += 1
-
End If
-
sh = lg.CoverShapes(i)
-
sh.Viewport.Width = w
-
sh.Viewport.Height = h
-
sh.Viewport.X = 20 + x * (15 + w)
-
sh.Viewport.Y = 65 + y * (15 + h)
-
-
sh = lg.CoverShapes(i + 1)
-
sh.Viewport.Width = w
-
sh.Viewport.Height = h
-
sh.Viewport.X = 20 + x * (15 + w)
-
sh.Viewport.Y = 65 + y * (15 + h)
-
x += 1
-
Next