Please add following lines to above methode to get better Scaling-Experience
BtnHeight := MulDiv(BtnHeight, M, D);
BtnWidth := MulDiv(BtnWidth, M, D);
LargeBtnWidth := MulDiv(LargeBtnWidth, M, D);
LargeBtnHeight := MulDiv(LargeBtnHeight, M, D);
And please check the line:
Height := Height - MulDiv(BtnHeight, M-D, D);
It doesn't make much sense for me.