The motion of electrons in a cylindrical magnetic field with the gradient-type potential is considered. The motion of electrons in the cylindrical magnetic field with the gradient-type potential is considered. It is found that in the selected field, the initial motion of electrons along the longitudinal axis is converted into motion along the radius. It is determined that such the transformation is due to the action of a solenoidal magnetic field with large longitudinal gradient. The transformation of the longitudinal direction of motion into the transverse one turned out to be stable in the energy range of 20...55 keV of electrons and in the range of 5...50 mm of radial dimensions of the particle beam. The main dependences of the motion of the electron beam in the given solenoidal magnetic field are studied with the help of the software tool. The results of numerical simulation of electron trajectories in the gradient magnetic field with the circular secondary emission cathode located in the middle of the system are presented. To study the mechanism of stability with respect to magnetic field, two experimentally realized magnetic fields were used. Based on these two fields, arrays of additional 4 fields are numerically synthesized. For the set of 6 named fields, the operation of the gun, in which the particle undergoes the stable transformation of the direction of motion, is numerically studied. It is shown that for the given electron energy and the fixed magnetic field, the parameter that determines the rotation of the particles is the magnetic field gradient at the boundary of the entry region. It is found that the rotation effect takes place for the considered range of radial beam sizes, which leads to particle focusing. The possibility is shown to control the vertical coordinate of the focused beam on the basis of the field adjustment, thereby giving the interpretation of the pore dependence of the registration of electrons on the detector. The dependence of the formation of the final distribution of particles on the amplitude and gradient of the magnetic field along the axis of the system is studied. The results of numerical simulation on the motion of the electron beam are presented. Based on the model of electron flow motion, the characteristics of the resulting electron beam are considered. It is shown that the beam, having radial dimensions of 5...50 mm, is transformed and focused vertically on the area of 1 mm.