在VB中选择/可编辑图表中的标签

时间:2014-07-29 12:32:17

标签: vb.net text mschart inline-editing

就像在图表的Excel中一样,您可以双击标题,系列名称或轴标签,然后您就可以输入该空间。我需要做什么才能为我的图表做到这一点?无知从哪里开始。似乎我可能要创建一个自定义标签?

3 个答案:

答案 0 :(得分:0)

您必须使用TextBoxLabel。单击TextBox时立即显示Label,再次点击TextBox时隐藏TextBox。默认情况下隐藏TextBox。将LabelShow放在一起。

以下是TextBox Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click Label1.Hide() TextBox1.Show() TextBox1.Text = Label1.Text End Sub 部分:

Hide

TextBox Private Sub TextBox1_Click(sender As Object, e As EventArgs) Handles TextBox1.Click Label1.Show() TextBox1.Hide() Label1.Text = TextBox1.Text End Sub 部分:

{{1}}

希望它有所帮助! 链接:https://sg.answers.yahoo.com/question/index?qid=20090228061555AAvfLkQ

答案 1 :(得分:0)

使用图表的HitTest方法。

Imports System.Windows.Forms.DataVisualization.Charting
Public Class Form1

    Private Sub Chart1_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles Chart1.MouseDoubleClick
        Dim h As HitTestResult = Chart1.HitTest(e.X, e.Y) 'Perform the HitTest with the mouse position that was clicked
        If h.ChartElementType = ChartElementType.AxisTitle OrElse _
            h.ChartElementType = ChartElementType.Axis Then 'Check the type of the element of the chart that was clicked
            Dim s As String = InputBox("Please enter a new title!", "", h.Axis.Title) 'Prompt for a new title
            If s <> "" Then h.Axis.Title = s 'Assign the new title
        End If
    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        For i = 1 To 20 'Put some data in the chart to make the axes visible
            Chart1.Series(0).Points.AddXY(i, i ^ 2)
        Next
    End Sub
End Class

您基本上使用HitTest方法的鼠标位置。 ChartElementType定义在该位置单击的元素。如果它是轴的标题或轴本身,它将提示您输入新标题的InputBox并分配此标题。

InputBox已经很老了,不应该真的使用但是我很懒,它有效: - )

答案 2 :(得分:0)

显然,我所指的是DataVisualization.Charting.TextAnnotation中的生活。除此之外,还有更多类型的注释。

TextAnnotation允许:AnchorMoving,Moving,PathEditing,Resizing,Selection和TextEditing。我正在寻找所有这些。

简单设置:

Dim anno As New DataVisualization.Charting.TextAnnotation
anno.AllowTextEditing = true
anno.AllowSelecting = true
anno.AllowMoving = true
anno.AllowResizing = true
anno.x = 50
anno.y = 50
anno.text = "Your Text"
chart.annotations.add(xAxisAnno)
相关问题