G
Guest
Hi,
I'm trying to draw a standard windows forms control onto a form with a
transformation. Before drawing the control I'm applying a world
transformation to the graphics object, but the results seem to be
unpredictable. Depending on the control my transformation seems to be
applied incompletely. For example, buttons are translated as I'd expect but
not scaled or rotated.
The easiest way to demonstrate this is to extend Bob Powell's excellent
animation demo from http://www.bobpowell.net/animation.htm
To see what I mean, add this class to Form1.cs in the demo:
public class ButtonShape : Shape
{
private class MyButton : Button
{
public void Draw(Graphics g)
{
PaintEventArgs args = new PaintEventArgs(g, new Rectangle(0,
0, Width, Height));
base.OnPaintBackground(args);
base.OnPaint(args);
}
}
private MyButton mb = new MyButton();
public override void RenderObject(Graphics g)
{
mb.Draw(g);
}
}
And modify the Form1 contstructor to add some ButtonShapes:
switch(r.Next(4))
{
// ... snip ....
case 3:
s = new ButtonShape();
break;
// ...
}
After making these modifications I get some buttons floating around with the
other shapes, but they do not rotate as the others do.
Anyone have any suggestions? Is it just not possible to apply a
transformation to a control because of the way they are drawn?
Thanks,
-Merit Wilkinson
I'm trying to draw a standard windows forms control onto a form with a
transformation. Before drawing the control I'm applying a world
transformation to the graphics object, but the results seem to be
unpredictable. Depending on the control my transformation seems to be
applied incompletely. For example, buttons are translated as I'd expect but
not scaled or rotated.
The easiest way to demonstrate this is to extend Bob Powell's excellent
animation demo from http://www.bobpowell.net/animation.htm
To see what I mean, add this class to Form1.cs in the demo:
public class ButtonShape : Shape
{
private class MyButton : Button
{
public void Draw(Graphics g)
{
PaintEventArgs args = new PaintEventArgs(g, new Rectangle(0,
0, Width, Height));
base.OnPaintBackground(args);
base.OnPaint(args);
}
}
private MyButton mb = new MyButton();
public override void RenderObject(Graphics g)
{
mb.Draw(g);
}
}
And modify the Form1 contstructor to add some ButtonShapes:
switch(r.Next(4))
{
// ... snip ....
case 3:
s = new ButtonShape();
break;
// ...
}
After making these modifications I get some buttons floating around with the
other shapes, but they do not rotate as the others do.
Anyone have any suggestions? Is it just not possible to apply a
transformation to a control because of the way they are drawn?
Thanks,
-Merit Wilkinson