C#: Flip image horizontally

2020-07-09 09:04发布

问题:

What I'm trying to do is, to flip image horizontally on radio button click.

private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
    arrow.Image.RotateFlip(RotateFlipType.RotateNoneFlipX);
}

private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
    arrow.Image.RotateFlip(RotateFlipType.RotateNoneFlipX);
}

The code above doesn't flip image: image stays as it is. What am I missing?

回答1:

You need to cause it to redraw, you can force this manually by doing

 private void radioButton1_CheckedChanged(object sender, EventArgs e)
 {
     arrow.Image.RotateFlip(RotateFlipType.RotateNoneFlipX);
     arrow.Invalidate() ;
 }

You should also only have this on one of the radio buttons, not both, otherwise they'll negate each other, so replace your current stuff with the above. Just verified it works under vs2005, don't have vs2010 handy