Is it possible to rotate a button control in WinForms?

前端 未结 5 1446
不思量自难忘°
不思量自难忘° 2020-12-04 00:58

Is it possible to rotate a button or any control at a particular angle in WinForms? If so, how?

5条回答
  •  一向
    一向 (楼主)
    2020-12-04 01:31

    You can't rotate controls. That's simply not supported by the native API controls that WinForms uses.

    And one might wonder why it even should be supported. What could you possibly be trying to do that you'd need to rotate a button control? It would be much easier to draw it in a different place with a different shape in the first place, rather than trying to rotate an existing control. (Do note that you can also resize and reposition a control at run-time, if that would fit your needs. Investigate the Size and Location properties.)

    The only workaround is to draw the control's image to a bitmap, hide the control, and draw the bitmap onto the form in the location you want it to appear. Of course, that won't result in a control that the user can interact with. They won't be able to click an image of a button, because it's not a real button. If that's acceptable to you, you should probably be using an image in the first place, rather than a button.

提交回复
热议问题