2017年12月10日 星期日

vb2010 正弦波 FillEllipse

     vb2010 正弦波 FillEllipse



來源
http://hanatyan.sakura.ne.jp/vbnetbbs/wforum.cgi?mode=allread&no=11658&page=0

'----------------------------------------------------------------------------------------
Imports System.Windows.Forms.DataVisualization.Charting

Public Class Form1

    Dim series1 As New Series() 'SIN
    Dim series2 As New Series() '任意
    Dim xval() As Double 'X軸存儲
    Dim yval() As Double '軸存儲

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load

        Label1.BackColor = Color.Red
        Label2.BackColor = Color.Red

        '圖表控制對象
        Chart1.Series.Clear()

        '添加數據系列
        Chart1.Series.Add(series1) 'SIN
        Chart1.Series.Add(series2)


        '內部數據的初始化
        series1.Points.Clear()
        series2.Points.Clear()


        With Chart1.ChartAreas(0).AxisX
            '補充行每10點顯示一次
            .MinorGrid.Enabled = True  '除非設置為True,否則不要顯示
            .Title = "X"
            .MinorGrid.Interval = 100
            .MinorGrid.LineDashStyle = DataVisualization.Charting.ChartDashStyle.Dash
            .LabelStyle.Format = "0.0"
        End With


        With Chart1.ChartAreas(0).AxisY 'Y軸の設定
            .TitleForeColor = Color.Red
            .Title = "sin(X)"  '設置標題文本
            .LineColor = Color.Red
            .MajorGrid.LineColor = Color.Red
            .LabelStyle.ForeColor = Color.Red
            .MajorGrid.LineDashStyle = DataVisualization.Charting.ChartDashStyle.Solid
            .LabelStyle.Format = "0.0"
            .Enabled = AxisEnabled.True '激活第一軸
        End With


        '傳說
        Chart1.Series(0).LegendText = "sin(X)"



        ' 圖的類型是散點圖(sin Chart)
        With series1
            .ChartType = SeriesChartType.Point
            .MarkerSize = 5
            .MarkerStyle = MarkerStyle.Circle
            .MarkerBorderColor = Color.Black
            .MarkerBorderWidth = 0.1
            .MarkerColor = Color.Blue
            .XAxisType = AxisType.Primary
            .YAxisType = AxisType.Primary

            .Enabled = True
        End With


        ' 圖的類型是散點圖(任意Point Chart)
        With series2
            .ChartType = SeriesChartType.Point
            .MarkerSize = 20
            .MarkerStyle = MarkerStyle.Circle
            .MarkerBorderColor = Color.Black
            .MarkerBorderWidth = 0.1
            .MarkerColor = Color.Green
            .XAxisType = AxisType.Primary
            .YAxisType = AxisType.Primary
            .Enabled = True
        End With

        Dim k As Integer = 0 '存儲陣列的地址計數器
        For i = 0 To 10 Step 0.01
            ReDim Preserve xval(k) '更改數組元素的數量
            xval(k) = i 'X軸値存儲
            ReDim Preserve yval(k) '更改數組元素的數量
            yval(k) = Math.Sin(xval(k)) 'Y軸値存儲

            series1.Points.AddXY(CDbl(xval(k)), yval(k)) 'SIN波形圖

            k = k + 1
        Next

    End Sub

    Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        '使Label控件的父級控件圖表控件
        Label1.Parent = Chart1
        '讓Label控件的父控件成為圖片控件
        Label2.Parent = PictureBox1

        series2.Points.Clear()  ' 內部數據的初始化
        series2.Points.AddXY(8, 1) '打点

        Me.Label1.Location = New Point(8, 1)

        Dim objBrush = New SolidBrush(System.Drawing.Color.Blue)
        Dim objGrp As Graphics = PictureBox1.CreateGraphics

        ' 繪製一個橢圓
        objGrp.FillEllipse(objBrush, 500, 50, 20, 20)

        Label2.Location = New Point(500, 50)

        ' 免費資源
        objBrush.Dispose()
        objGrp.Dispose()

    End Sub



    '----------------------------------------------------------------------------------------

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        End
    End Sub
End Class

沒有留言:

張貼留言

WOKWI LED + MQTT Node-Red SQLite

WOKWI LED + MQTT Node-Red SQLite const char *mqtt_broker = "broker.mqtt-dashboard.com" ; const char *topic1 = "alex9ufo/e...