The electron gun generates electrons and focuses them into a narrow beam. This beam is then accelerated towards the specimen using an anode. The beam passes through a series of electromagnetic lenses that focus and direct it onto the specimen. When the electrons interact with the specimen, they produce various signals that can be detected and converted into high-resolution images.