在imagelist中显示饼图

时间:2015-02-20 13:06:38

标签: visual-studio-2010

我正在vb.net中开发一个项目,我正在使用图像列表制作饼图,但问题是用于输入数据的文本框是在另一个图像中,输出应该显示在另一个图像中。我得到一个饼图,如果我在一个单一的形式。 PLZ帮助我获取代码以获取该值。

1 个答案:

答案 0 :(得分:0)

它是一个windows application.i hv使用了imagelist而不是使用tab。饼图应该显示在第一个图像部分中,而饼图显示的值是在另一个图像中。

饼图的代码在这里 - Imports Charting = System.Windows.Forms.DataVisualization.Charting Imports ComponentModel = System.ComponentModel Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)     form2.show() 结束子 公共类Form3

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

End Sub

结束班

Public Class Form1     '使用BindingList来表示列表更改     Private WithEvents Sectors As New ComponentModel.BindingList(Of SectorItem)

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    ' setting text just for demo purposes
    'TextBox1.Text = "10"
    'TextBox2.Text = "5"

    ' define a piechart series
    Dim PieSeries1 As New Charting.Series("Pie1")
    PieSeries1.ChartType = Charting.SeriesChartType.Pie
    PieSeries1.CustomProperties = "PieLabelStyle=Disabled"

    Chart1.Series.Clear()                  ' reset the chart Series collection
    Chart1.Series.Insert(0, PieSeries1)    ' add PieSeries1 to Chart1

    ' add the SectorItems
    Sectors.Add(New SectorItem(TextBox1, "Sector 1"))
    Sectors.Add(New SectorItem(TextBox2, "Sector 2"))
    Sectors.Add(New SectorItem(TextBox3, "Sector 3"))
    Sectors.ResetItem(0) ' force a ItemChanged event to set the Points DataBinding
End Sub

''' <summary>
''' Updates the chart data each time any of the SectorItems changes due to a Name Change or the
''' databound TextBox.Text changes   
''' </summary>
Private Sub sectors_ListChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ListChangedEventArgs) Handles Sectors.ListChanged
    If e.ListChangedType = ComponentModel.ListChangedType.ItemChanged Then
        Chart1.Series("Pie1").Points.DataBind(Sectors, "", "Value", "Label=Name")
    End If
End Sub

''' <summary>
''' a helper class for binding a TextBox value to a chart.  
''' </summary>
Private Class SectorItem
    ' implement INotifyPropertyChanged to signal changes to the property values
    Implements System.ComponentModel.INotifyPropertyChanged
    Public Event PropertyChanged(ByVal sender As Object, ByVal e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged

    Public Sub New(ByVal tb As TextBox, ByVal Name As String)
        Me._Name = Name
        Double.TryParse(tb.Text, _Value)
        ' bind Value to the TextBox.Text Property
        ' You may want to use DataSourceUpdateMode.OnValidation instead of  DataSourceUpdateMode.OnPropertyChanged
        ' OnPropertyChanged fires on each change as you type in the TextBox
        tb.DataBindings.Add("Text", Me, "Value", True, DataSourceUpdateMode.OnPropertyChanged)
    End Sub

    Private Sub NotifyPropertyChanged(ByVal info As String)
        RaiseEvent PropertyChanged(Me, New ComponentModel.PropertyChangedEventArgs(info))
    End Sub

    Private _Name As String
    Public Property Name() As String
        Get
            Return _Name
        End Get
        Set(ByVal value As String)
            ' only singal change if value actually changes
            Dim notify As Boolean = Not String.Equals(_Name, value)
            _Name = value
            If notify Then NotifyPropertyChanged("Name")
        End Set
    End Property 'Name

    Private _Value As Double
    Public Property Value() As Double
        Get
            Return _Value
        End Get
        Set(ByVal value As Double)
            ' only singal change if value actually changes
            Dim notify As Boolean = (_Value <> value)
            _Value = value
            If notify Then NotifyPropertyChanged("Value")
        End Set
    End Property 'Value
End Class ' SectorItem

结束班

相关问题