是否可以旋转的WinForms一个按钮控件?控件、按钮、WinForms

2023-09-02 21:41:03 作者:小卑鄙 ?

时可以旋转按钮或在WinForms的特定角度的任何控制?如果是这样,怎么样?

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

推荐答案

您不能旋转控制。这根本不​​支持原生API控制的WinForms的使用。

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

和人们可能会问,为什么它甚至应的支持。还有什么比你可能会尝试这样做,你需要旋转按钮控制?这将是更容易绘制在不同的地方有不同的形状摆在首位,而不是试图旋转现有的控制。 (请注意,你也可以调整大小和位置在运行时的控制,如果这将满足您的需求。调查的Size和Location属性。)

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.