用代码设置布局
在窗口增加一个Gauges控件,然后增加一下空白的径向仪表,再增加一个按钮用于运行下面的代码:
Dim gg
As WinForm.Gauges
= e.Form.Controls("Guages1")
Dim rg
As RadialGauge
= gg.RadialGauge
rg.Minimum = -30
rg.Maximum = 40
rg.StartAngle = 1 - 5
rg.SweepAngle = 30
rg.PointerOriginY = 3.5
rg.Radius = 3.7
rg.Viewport.AspectRatio = 2.1
rg.Viewport.AspectPinY = 0.5
Dim sc
As New GaugeSector
'定义一个Sector形状
sc.Name =
"sc" '设置形状的Name属性
sc.OuterRadius = 93
sc.CenterRadius = 3
sc.InnerRadius = 220
sc.InnerOffset = -150
sc.CornerRadius = 2
sc.StartAngle =
-15
sc.SweepAngle = 30
sc.Border.Thickness = 0.5
sc.Border.Color = Color.DarkSeaGreen
sc.Filling.BrushType =
C1.Win.C1Gauge.C1GaugeBrushType.Gradient
sc.Filling.Color = Color.Lavender
sc.Filling.Color2 = Color.LightSlateGray
sc.Gradient.Direction =
C1.Win.C1Gauge.C1GaugeGradientDirection.RadialInner
rg.FaceShapes.Add(sc)
'将Sector添加到FaceShapes集合中
rg.Pointer.Visible =
False '临时隐藏指针
rg.Cap.Visible =
False '隐藏cap
上述代码涉及的属性和类型,我们前面都介绍过了,这段代码完成了仪表的布局,并动态增加了一个Sector用于仪表的轮廓,运行后得到:
提示:如果你打算用代码从零开始搭建一个仪表,那么建议先通过窗口设计器设计好这个仪表,然后保存为模板,照着模板写代码,简直太轻松了。