0
如何旋转(90度)面板控件?我知道这是非常简单的WPF,但我不能使用它。 你知道WinForm面板控制的这种方式吗? 谢谢大家!在WinForm中旋转面板
如何旋转(90度)面板控件?我知道这是非常简单的WPF,但我不能使用它。 你知道WinForm面板控制的这种方式吗? 谢谢大家!在WinForm中旋转面板
您将不得不重写OnPaint,然后使用GDI手动绘制panel上的所有控件。我从来没有做过旋转,但我已经做了一些像下拉菜单的定制重绘。您需要为面板上的每种控件类型编写自定义OnPaints。
所以更多的这一点,因为我只是尝试了我的自我...我不认为你可以自定义绘制大多数常用控件。 WPF是一种不同的动物,旨在支持这种类型的事情。当这些控件进行绘制时,它们会在封面下执行操作,并且没有任何可以执行的操作。我能够绘制和旋转面板,但是我无法像复选框那样执行其他控件。
public class RotatePanel : Panel, IRotate
{
public RotatePanel() : base()
{
Angle = 0;
}
protected override void OnPaint(PaintEventArgs e)
{
using (Graphics g = this.CreateGraphics())
{
foreach (IRotate control in this.Controls)
{
control.Angle = Angle;
}
g.RotateTransform(Angle);
g.DrawRectangle(new System.Drawing.Pen(new SolidBrush(Color.Black), 2f), 4f, 4f, 10f, 10f);
g.DrawRectangle(new System.Drawing.Pen(new SolidBrush(Color.Azure), 2f), 14f, 14f, 30f, 30f);
g.Flush();
}
base.OnPaint(e);
}
protected override void OnPaintBackground(PaintEventArgs e)
{
base.OnPaintBackground(e);
}
public float Angle
{
get;
set;
}
}
public interface IRotate
{
float Angle { get; set; }
}
public class RotateCheckBox : CheckBox, IRotate
{
public float Angle { get; set; }
public RotateCheckBox():base()
{
Angle = 0;
}
protected override void OnPaint(PaintEventArgs pevent)
{
pevent.Graphics.RotateTransform(this.Angle);
pevent.Graphics.Flush();
base.OnPaint(pevent);
}
}
只是出于好奇,为什么你不能使用WPF?你知道ElementHost,对吗?我很感兴趣,因为我们正在考虑在我们的WinForms应用程序中添加一些WPF,并且我很好奇你为什么不能。 – 2010-10-26 22:39:05