private void textAlignCenterToolStripMenuItem_Click(object sender, EventArgs e)
{
lastSelected = "textAlignCenter";
OnPaintAction = cr =>
{
string text = "cairo";
TextExtents extents;
double x, y;
cr.SelectFontFace("Microsoft Sans Serif", FontSlant.Normal, FontWeight.Normal);
cr.SetFontSize(52.0);
extents = cr.TextExtents(text);
x = 128.0 - (extents.Width / 2 + extents.XBearing);
y = 128.0 - (extents.Height / 2 + extents.YBearing);
cr.MoveTo(x, y);
cr.ShowText(text);
/* draw helping lines */
cr.SetSourceRGBA(1, 0.2, 0.2, 0.6);
cr.LineWidth = 6.0;
cr.Arc(x, y, 10.0, 0, 2 * Math.PI);
cr.Fill();
cr.MoveTo(128.0, 0);
cr.RelLineTo(0, 256);
cr.MoveTo(0, 128.0);
cr.RelLineTo(256, 0);
cr.Stroke();
};
Invalidate();
}