We report measurements of charm-mixing parameters based on the decay-time-dependent ratio of $D^0to K^+pi^-$ to $D^0to K^-pi^+$ rates. The analysis uses a data sample of proton-proton collisions corresponding to an integrated luminosity of $5.0$ fb$^{-1}$ recorded by the LHCb experiment from 2011 through 2016. Assuming charge-parity (CP) symmetry, the mixing parameters are determined to be $x^2=(3.9 pm 2.7) times10^{-5}$, $y=(5.28 pm 0.52) times 10^{-3}$, and $R_D=(3.454 pm 0.031)times10^{-3}$. Without this assumption, the measurement is performed separately for $D^0$ and $overline{D}{}^0$ mesons, yielding a direct CP-violating asymmetry $A_D =(-0.1pm9.1)times10^{-3}$, and magnitude of the ratio of mixing parameters $1.00< |q/p| <1.35$ at the $68.3%$ confidence level. All results include statistical and systematic uncertainties and improve significantly upon previous single-measurement determinations. No evidence for CP violation in charm mixing is observed.