Based on evolutionary algorithm and first-principles calculation, crystal structures of quaternary compound HfxTa8-xC7N (x=1-7) were predicted. Similar to binary HfC and TaC, these compounds have a rock-salt structure. The calculation of mechanical properties shows that: With the increase of valence electron concentration (VEC), the bulk modulus of HfxTa8-xC7N increased gradually; At VEC=8.875, the shear modulus and elastic modulus are the largest; The Vickers hardness reaches the maximum at VEC=8.25. Therefore, the quaternary HfxTa8-xC7N compounds with excellent comprehensive mechanical properties can be obtained with the design of VEC. Finally, electronic properties of HfxTa8-xC7N compounds were calculated. Relations between mechanical properties and electronic properties were analyzed.