The integrated transverse momentum change of a charged particle in the rf field of a cavity can be related to the change of its voltage gain due to a virtual transverse displacement of its orbit. Formulas for the particle deflection are derived, which are a generalisation of the Panofsky-Wenzel theorem to an arbitrary cavity shape and to curved orbits through the cavity. In addition, some useful formulas for the transverse and longitudinal focusing are presented.