0

I want to rotate a whole button at the same time with image inside. I 'm using this code for rotating my button to left.

 int y = button1.Size.Width; //i'm taking  position y
 int x = button1.Height;     //i'm taking  position x
 button1.Size = new Size((x+y)-y , (x + y) - x); //now i rotate it

But the image inside remains the same. How can i rotate image inside at the same time with button. And how can i take image position.(i mean if its rotated or not)

Dimis
  • 15
  • 6
  • 1
    You're not really rotating the button, you're just changing the width and height. – Rick S Feb 21 '17 at 18:43
  • 2
    You can do that with WPF, but not with WinForms. Please specify "winforms" as tag, if it applies. – Olivier Jacot-Descombes Feb 21 '17 at 18:45
  • 1
    Here are some answers for rotating images in winforms: http://stackoverflow.com/questions/2163829/how-do-i-rotate-a-picture-in-winforms -- but rotating the whole control may be more than the framework can bear. – 15ee8f99-57ff-4f92-890c-b56153 Feb 21 '17 at 18:46
  • 2
    is it sufficient to support rotations of 0/90/180/270 degrees? then I would suggest to just provide 2-4 pre-rotated versions of the image, and reassign the image property as you change the button's size. – Cee McSharpface Feb 21 '17 at 18:50
  • 2
    @dlatikay: But these rotations are very simple and efficient to do at runtime and don't introduce distortion in the process, likely even faster than reading an extra image from the disk. Just call the `RotateFlip` method when assigning the `Image` property. – Ben Voigt Feb 21 '17 at 18:57
  • This is what i'm thinking to do but i'm stacked! When i will press rotation button i want give a string with image name and not the image direct to Properties.Resources.(cause i'm using dynamic button.)Example Image Rot45=Properties.Resources."ImageRotated45"; And then to use it in my dynamic button.EXample dynamicButton.BackgroundImage = Properties.Resources.Rot45; I get Error Resources does not contain definition for Rot45 – Dimis Feb 21 '17 at 19:01
  • ...and now for something completely different... http://stackoverflow.com/a/1192077/1132334 and http://stackoverflow.com/a/11011308/1132334 – Cee McSharpface Feb 21 '17 at 20:10

1 Answers1

0

use this technique: button1.Image.RotateFlip((RotateFlipType.Rotate90FlipXY));

SWIK
  • 714
  • 7
  • 12