[VB 2008] Rotate a control

V

vino

Hello,
I have created my proper control and i would to rotate it.
In the paint event of my object, i have written :

Dim graph As Graphics = myObject.CreateGraphics
myMatrix = New System.Drawing.Drawing2D.Matrix
myMatrix.Rotate(45, System.Drawing.Drawing2D.MatrixOrder.Append)
graph.Transform = myMatrix

but it don't work.
The object i have created (a 2D wall of a house) no rotate.
If someone say how to resolve it.

Thanks.
 
H

Herfried K. Wagner [MVP]

vino said:
I have created my proper control and i would to rotate it.
In the paint event of my object, i have written :

Dim graph As Graphics = myObject.CreateGraphics
myMatrix = New System.Drawing.Drawing2D.Matrix
myMatrix.Rotate(45, System.Drawing.Drawing2D.MatrixOrder.Append)
graph.Transform = myMatrix

but it don't work.
The object i have created (a 2D wall of a house) no rotate.

You have to set the transformation on the 'Graphics' object you are using to
draw the content, typically in 'OnPaint' or the 'Paint' event handler.
 
V

vino

Thank you Herfried K. Wagner for your answer.

But i have any idea how to do it.
The rotation value is set by the user and he can change it whenever and my
personal component has to rotate immediately.

Thanks.
 
K

kimiraikkonen

Thank you Herfried K. Wagner for your answer.

But i have any idea how to do it.
The rotation value is set by the user and he can change it whenever and my
personal component has to rotate immediately.

Thanks.

BTW, what type is your object to be rotated? A kind of standard
control in toolbox?

Thanks,

Onur Güzel
 
V

vino

No, it is a personalised control i have made named "Fenetre" and imported in
my project.
It contain an object PowerPacks.RectangleShape and a Label whose represent a
house windows.

Thanks.

Gilles Lautrou.
 
H

Herfried K. Wagner [MVP]

vino said:
No, it is a personalised control i have made named "Fenetre" and imported
in
my project.
It contain an object PowerPacks.RectangleShape and a Label whose represent
a
house windows.

Windows Forms controls unfortunately cannot be rotated. However, you can
rotate WPF-based controls.
 
V

vino

Ok.
If i understand, unfortunately i have to work with WPF.
I have ever tryied it but it seems to be difficult to learn how to
manipulate objects.
If you are a few complete samples of WPF i am interested in.

Thanks.

Gilles
 
K

kimiraikkonen

Here is rotating a button 90 degrees in WPF...

<Button HorizontalAlignment="Center" VerticalAlignment="Center" Content="Hi This is a button">
<Button.LayoutTransform>
<RotateTransform Angle="90" />
</Button.LayoutTransform>
</Button>

Copy this into a tool like XamlPad and you will have a button centered and
rotated 90 degrees...

I got a primitive idea, if you need to rotate a button just for 90
degrees, replace height and width. For example a newly placed button
is sized about 75;23. Then you can do:

Button1.Size = New Size(23, 75)

..and now it seems like it's rotated by 90 degrees. :)

Thanks,

Onur Güzel
 
K

kimiraikkonen

Except that the content is not rotated...

Yes, you need to wrap the text of button though it's wrapped
automatically but i found out that "t" seems double as next in a 23;75
sized button with default Sans-Serif Font(8 pt).

Thanks,

Onur Güzel
 
K

kimiraikkonen

The wpf version actually rotates the text as well - not just wraps it intoa
column.  Here is a complete example that spins a button 360 degrees overa
half a second when it is clicked - and it uses NO procedural code....

<Page
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
        <Grid>
        <Button HorizontalAlignment="Center"
                VerticalAlignment="Center"
                Content="Hi This is a button"
                RenderTransformOrigin=".5,.5">
            <Button.LayoutTransform>
                <RotateTransform Angle="0" />
            </Button.LayoutTransform>
            <Button.Triggers>
                <EventTrigger RoutedEvent="Button.Click">
                    <EventTrigger.Actions>
                        <BeginStoryboard>
                            <Storyboard TargetProperty="LayoutTransform.Angle">
                                <DoubleAnimation From="0" To="360" Duration="0:0:.5"/>
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger.Actions>
                </EventTrigger>
            </Button.Triggers>
        </Button>
        </Grid>
</Page>

I have to wonder sometimes, why people are still using Windows forms at all :)
Actually, I know why - but, WPF is so much nicer.

Yeah, but my concern is that WPF *may* and probably require a greater
processor and graphic card than a simple Winform.

Thanks,

Onur Güzel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top