locked
absolute position RRS feed

  • Question

  • In this example i want to position the label "1" exactely at the beginnig of chart, but the position is not correct, it's always a little more; you need to add a chart and a label to form:

    Imports System.Windows.Forms.DataVisualization.Charting
    
    Public Class Form1
        Dim startgraph, graphend As Integer
        Dim x, y As Single
        Dim posiz As PointF
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Label1.Left = Chart1.Left
        End Sub
    
        Private Sub Chart1_PostPaint(sender As Object, e As ChartPaintEventArgs) Handles Chart1.PostPaint
            x = CSng(e.ChartGraphics.GetPositionFromAxis(Chart1.ChartAreas(0).Name, AxisName.X, Chart1.ChartAreas(0).AxisX.Minimum))
            y = CSng(e.ChartGraphics.GetPositionFromAxis(Chart1.ChartAreas(0).Name, AxisName.Y, 0))
            posiz = New PointF(x, y)
            posiz = e.ChartGraphics.GetAbsolutePoint(posiz)
            startgraph = posiz.X
    
            x = CSng(e.ChartGraphics.GetPositionFromAxis(Chart1.ChartAreas(0).Name, AxisName.X, Chart1.ChartAreas(0).AxisX.Maximum))
            y = CSng(e.ChartGraphics.GetPositionFromAxis(Chart1.ChartAreas(0).Name, AxisName.Y, 0))
            posiz = New PointF(x, y)
            posiz = e.ChartGraphics.GetAbsolutePoint(posiz)
            graphend = posiz.X
        End Sub
    End Class
    The process for determining the position may be wrong.

    Tuesday, August 18, 2020 2:11 PM

Answers

  • At start

    after clicking:

    now it is ok; i forgot the width of the label; buttor routine is now:

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Label1.Left = Chart1.Left - Label1.Width / 2
    End Sub
    Thanks, Enzo

    Tuesday, August 18, 2020 4:32 PM

All replies

  • Hi

    I can not see the effect you seem to talk about. Here is a graphic of a simple example.

    I set both the Chart and Label borders so that alignment could be easily seen.

    The code line to position the Label was:

    Label1.Location = New Point(Chart1.Left, 50)
    


    Regards Les, Livingston, Scotland

    Tuesday, August 18, 2020 2:47 PM
  • Hy,

    if you try the code you do not see the label "1" ? Add a chart and a label somewhere, the "1" will not corresponde to the beginning of chart.

    Enzo

    Tuesday, August 18, 2020 3:42 PM
  • Hi

    Using the code you posted amounts to exactly the same result as the code I posted.

    What is the significance of the "1" you mention?  Are you meaning Label1?

    If you can, post an image of the issue/effect you are seeing.

    I feel I am misunderstanding your problem.


    Regards Les, Livingston, Scotland

    Tuesday, August 18, 2020 3:54 PM
  • At start

    after clicking:

    now it is ok; i forgot the width of the label; buttor routine is now:

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Label1.Left = Chart1.Left - Label1.Width / 2
    End Sub
    Thanks, Enzo

    Tuesday, August 18, 2020 4:32 PM