The solenoids are widely used both in conventional magnets and superconducting magnets in the particle accelerators. The longitudinal fields along longitudinal direction of the solenoids are usually measured with the Hall probe measurement system. However, in some cases, the deviation between magnetic center and mechanical center of solenoid is another important parameter and has to be measured accurately. In this paper, a device is designed and developed to measure the center deviation of the solenoid, which can be both used in conventional magnets and superconducting magnets. After the device is finished, some tests are made in the solenoid to check whether the data is correct. For the numerical simulation and analysis of the magnetic field inside the solenoid, the TOSCA code was chosen right from start. The results of the analysis are compared to the result of the tests.