This reminds me of problem I had while developing one of my semestral projects in C# - 3D graphics modeller/ray tracer (you can place basic primitives or loaded meshes into scene and move/rotate/scale with them ... also if you wanna try it, don't forget to add light object - bind material with emissivity to object). First of all - http://www.otte.cz/Moderu.tar.gz - here is the C# project and code ... it's quite large for semestral project (and don't worry if you're not at university yet, you don't have to make this large projects, I just wanted to do so), and it's really slow ray tracer (I didn't have time to optimize it - it was created over 2 weekends, while also I had to do projects in Haskell).
But to the point - there is a code to calculate line-to-line distance - and also picking axis to move the body in editor. Basically the problem is same as yours, you want to find line-to-line distance between a ray from camera position in direction of "mouse position" on screen, and each edge of triangle in which you're going to select an edge (e.g. probably triangle under your cursor, but you might also need to search it's neighbors). All the math is actually in the code - and I think it's also a bit commented (so you can find the stuff easily) + it's in C# and thats very descriptive language (oh a strong effect of C++ can be seen on the code, as I name stuff like in C++ - don't blame me for this please).