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

Re: Transforming Controls? by Bob

Bob
Thu Nov 10 14:47:53 CST 2005

Controls are generally windows wrapped by a bit of .net wizardry. They are
just Win32 things.

To change the orientation of a whole window is a driver-level thing and not
available to the ordinary developer.


--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.



"Merit" <Merit@discussions.microsoft.com> wrote in message
news:CF870DC6-9638-424A-9B28-FF4607BB96AD@microsoft.com...
> 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
>