I have two points that draw a line when connected. The line can be both vertical horizontal, vertical, or (most commonly) diagonal.
I would like to try text along this path. I’m using C# and WinForms, but I think that isn’t as important as some simple psuedo-code that may include some math (trig?) needed to find the angle of the path to align the text to.
Use Math.Atan2() to calculate the angle. Convert from radians to degrees by multiplying by 180 / Math.Pi. Getting the center of rotation for RotateTransform() is the critical step to get the text aligned properly with the line. r * Math.Cos(angle) for the X-offset from the line start point, r * Sin(angle) for the Y-offset where r is the offset from the line start point. Adjust by the font’s Height to get it above the line.