TrackBar Scale Image Link
我所做的事是修改的圖表和使用它的X軸的規模爲規模爲跟蹤條(見鏈接,圖像[我會嵌入圖像,但我無法得到它的工作])。圖像的上半部分是滑塊,下半部分是常規圖表對象,其屬性已更改,因此唯一可見的是其X軸。
以下是TrackBar和Chart的VS2010表單設計器代碼。這個例子會給你一個0到100的比例,可以很容易地調整大小以便與你的trackbar一致。你甚至可以把兩個控件放在一個面板中,以便它們可以很容易地調整爲一個(代碼是VB而不是C#):
Dim ChartArea2 As System.Windows.Forms.DataVisualization.Charting.ChartArea = New System.Windows.Forms.DataVisualization.Charting.ChartArea()
Dim Legend2 As System.Windows.Forms.DataVisualization.Charting.Legend = New System.Windows.Forms.DataVisualization.Charting.Legend()
Dim Series2 As System.Windows.Forms.DataVisualization.Charting.Series = New System.Windows.Forms.DataVisualization.Charting.Series()
Dim DataPoint2 As System.Windows.Forms.DataVisualization.Charting.DataPoint = New System.Windows.Forms.DataVisualization.Charting.DataPoint(0.0R, 0.0R)
Me.chart_slider = New System.Windows.Forms.DataVisualization.Charting.Chart()
Me.TrackBar1 = New System.Windows.Forms.TrackBar()
CType(Me.chart_slider, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.TrackBar1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'chart_slider
'
Me.chart_slider.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.chart_slider.BackColor = System.Drawing.Color.Transparent
ChartArea2.AxisX.LabelAutoFitMaxFontSize = 8
ChartArea2.AxisX.LabelAutoFitMinFontSize = 8
ChartArea2.AxisX.LineColor = System.Drawing.Color.Transparent
ChartArea2.AxisX.MajorGrid.Enabled = False
ChartArea2.AxisX.Maximum = 100.0R
ChartArea2.AxisX.Minimum = 0.0R
ChartArea2.AxisY.Interval = 1.0R
ChartArea2.AxisY.LineWidth = 0
ChartArea2.AxisY.MajorGrid.Enabled = False
ChartArea2.AxisY.MajorTickMark.Enabled = False
ChartArea2.AxisY.Maximum = 0.0R
ChartArea2.AxisY.Minimum = 0.0R
ChartArea2.AxisY.TitleForeColor = System.Drawing.Color.Transparent
ChartArea2.BackColor = System.Drawing.Color.Transparent
ChartArea2.InnerPlotPosition.Auto = False
ChartArea2.InnerPlotPosition.Height = 5.0!
ChartArea2.InnerPlotPosition.Width = 100.0!
ChartArea2.Name = "ChartArea1"
Me.chart_slider.ChartAreas.Add(ChartArea2)
Legend2.Enabled = False
Legend2.Name = "Legend1"
Me.chart_slider.Legends.Add(Legend2)
Me.chart_slider.Location = New System.Drawing.Point(186, 426)
Me.chart_slider.Name = "chart_slider"
Series2.ChartArea = "ChartArea1"
Series2.Legend = "Legend1"
Series2.Name = "Series1"
Series2.Points.Add(DataPoint2)
Me.chart_slider.Series.Add(Series2)
Me.chart_slider.Size = New System.Drawing.Size(441, 31)
Me.chart_slider.TabIndex = 160
Me.chart_slider.Text = "Chart1"
'
'TrackBar1
'
Me.TrackBar1.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.TrackBar1.Location = New System.Drawing.Point(191, 398)
Me.TrackBar1.Margin = New System.Windows.Forms.Padding(3, 3, 3, 0)
Me.TrackBar1.Name = "TrackBar1"
Me.TrackBar1.RightToLeftLayout = True
Me.TrackBar1.Size = New System.Drawing.Size(423, 45)
Me.TrackBar1.TabIndex = 1
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(690, 498)
Me.Controls.Add(Me.TrackBar1)
Me.Controls.Add(Me.chart_slider)
Me.Name = "Form1"
Me.Text = "Form1"
CType(Me.chart_slider, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.TrackBar1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
Me.PerformLayout()
一種黑客,但非常漂亮。提供一個很好的結果。正是我需要的!非常感謝!也許它可以用更通用的方式進行編碼,所以如果TrackBar的某些屬性發生變化,ChartArea會自動更改。 :-) – itmuckel 2016-07-22 09:16:45