Melt the butter in a large skillet over medium heat.
Add the onion and cook for 4 to 5 minutes, until softened.
Sprinkle the flour over the onions and stir constantly for about 1 minute.
Slowly pour in the milk and heavy cream, stirring well to keep the sauce smooth.
Add the corn, sugar, salt, and black pepper. Stir to combine.
Reduce the heat to medium-low and simmer for 10 to 12 minutes, stirring occasionally, until the sauce thickens and the corn is heated through.
Lightly mash some of the corn using the back of a wooden spoon to help thicken the mixture while leaving most of the kernels whole.
Cook for another 2 to 3 minutes, then taste and adjust the seasoning before serving.