Re: rotate drawing with matrix

From: Peter Proost (pproost_at_nospam.hotmail.com)
Date: 12/07/04


Date: Tue, 7 Dec 2004 16:55:35 +0100

Thanks, that's what I wanted to do Bob,

Greetz Peter

"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:u8zH4GH3EHA.3932@TK2MSFTNGP12.phx.gbl...
> Like this??
>
> (after my signature)
>
> --
> Bob Powell [MVP]
> Visual C#, System.Drawing
>
> 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.
>
>
> ------------------------------------------------------------------------
> Protected Overrides Sub OnPaint(ByVal e As
> System.Windows.Forms.PaintEventArgs)
>
>
>
> Dim mx As New Matrix
>
> mx.Translate((Me.ClientSize.Width / 2) - 150, (Me.ClientSize.Height / 2) -
> 150, MatrixOrder.Append)
>
> e.Graphics.Transform = mx
>
> e.Graphics.FillRectangle(brush, 100, 100, 100, 100)
>
> 'Place inside form paint event
>
> mx = New Matrix
>
> mx.RotateAt(hoek, New PointF(150, 150), MatrixOrder.Append)
>
> mx.Translate((Me.ClientSize.Width / 2) - 150, (Me.ClientSize.Height / 2) -
> 150, MatrixOrder.Append)
>
> e.Graphics.Transform = mx
>
> 'grote ster
>
> e.Graphics.DrawLine(pentje, 100, 100, 150, 0)
>
> e.Graphics.DrawLine(pentje, 150, 0, 200, 100)
>
> e.Graphics.DrawLine(pentje, 200, 100, 300, 150)
>
> e.Graphics.DrawLine(pentje, 300, 150, 200, 200)
>
> e.Graphics.DrawLine(pentje, 200, 200, 150, 300)
>
> e.Graphics.DrawLine(pentje, 150, 300, 100, 200)
>
> e.Graphics.DrawLine(pentje, 100, 200, 0, 150)
>
> e.Graphics.DrawLine(pentje, 0, 150, 100, 100)
>
> 'kleine ster
>
> e.Graphics.DrawLine(pentje, 100, 100, 150, 25)
>
> e.Graphics.DrawLine(pentje, 150, 25, 200, 100)
>
> e.Graphics.DrawLine(pentje, 200, 100, 275, 150)
>
> e.Graphics.DrawLine(pentje, 275, 150, 200, 200)
>
> e.Graphics.DrawLine(pentje, 200, 200, 150, 275)
>
> e.Graphics.DrawLine(pentje, 150, 275, 100, 200)
>
> e.Graphics.DrawLine(pentje, 100, 200, 25, 150)
>
> e.Graphics.DrawLine(pentje, 25, 150, 100, 100)
>
> 'kleinere ster
>
> e.Graphics.DrawLine(pentje, 100, 100, 150, 50)
>
> e.Graphics.DrawLine(pentje, 150, 50, 200, 100)
>
> e.Graphics.DrawLine(pentje, 200, 100, 250, 150)
>
> e.Graphics.DrawLine(pentje, 250, 150, 200, 200)
>
> e.Graphics.DrawLine(pentje, 200, 200, 150, 250)
>
> e.Graphics.DrawLine(pentje, 150, 250, 100, 200)
>
> e.Graphics.DrawLine(pentje, 100, 200, 50, 150)
>
> e.Graphics.DrawLine(pentje, 50, 150, 100, 100)
>
> 'kleinste ster
>
> e.Graphics.DrawLine(pentje, 100, 100, 150, 75)
>
> e.Graphics.DrawLine(pentje, 150, 75, 200, 100)
>
> e.Graphics.DrawLine(pentje, 200, 100, 225, 150)
>
> e.Graphics.DrawLine(pentje, 225, 150, 200, 200)
>
> e.Graphics.DrawLine(pentje, 200, 200, 150, 225)
>
> e.Graphics.DrawLine(pentje, 150, 225, 100, 200)
>
> e.Graphics.DrawLine(pentje, 100, 200, 75, 150)
>
> e.Graphics.DrawLine(pentje, 75, 150, 100, 100)
>
> End Sub
>
> ------------------------------------------------------------------------
>
>
> "Peter Proost" <pproost@nospam.hotmail.com> wrote in message
> news:Od8Yau32EHA.924@TK2MSFTNGP14.phx.gbl...
> > Hi group,
> >
> >
> > I got the following piece of code which draws a square with stars round
> it,
> > now I want the stars to rotate round the square, I can do this with the
> > mx.rotate and a timer and an angle, but this rotates the whole drawing
of
> > the stars but what I realy want is for the stars to rotate round it's
> center
> > point, is this possible? I hope I was clear enough in my explanation.
> >
> > Thanks in advance
> >
> > Peter
> >
> >
> >
> > Imports System.Drawing.Drawing2D
> >
> > Private pentje As New Pen(Color.White)
> > Private brush As New SolidBrush(Color.White)
> > Private hoek As Single
> >
> >
> > e.Graphics.FillRectangle(brush, 100, 100, 100, 100)
> >
> > 'Place inside form paint event
> > 'Dim mx As New Matrix
> > 'mx.Rotate(hoek, MatrixOrder.Append)
> > 'mx.Translate(Me.ClientSize.Width / 2, Me.ClientSize.Height / 2,
> > MatrixOrder.Append)
> > 'e.Graphics.Transform = mx
> >
> > 'grote ster
> > e.Graphics.DrawLine(pentje, 100, 100, 150, 0)
> > e.Graphics.DrawLine(pentje, 150, 0, 200, 100)
> > e.Graphics.DrawLine(pentje, 200, 100, 300, 150)
> > e.Graphics.DrawLine(pentje, 300, 150, 200, 200)
> > e.Graphics.DrawLine(pentje, 200, 200, 150, 300)
> > e.Graphics.DrawLine(pentje, 150, 300, 100, 200)
> > e.Graphics.DrawLine(pentje, 100, 200, 0, 150)
> > e.Graphics.DrawLine(pentje, 0, 150, 100, 100)
> > 'kleine ster
> > e.Graphics.DrawLine(pentje, 100, 100, 150, 25)
> > e.Graphics.DrawLine(pentje, 150, 25, 200, 100)
> > e.Graphics.DrawLine(pentje, 200, 100, 275, 150)
> > e.Graphics.DrawLine(pentje, 275, 150, 200, 200)
> > e.Graphics.DrawLine(pentje, 200, 200, 150, 275)
> > e.Graphics.DrawLine(pentje, 150, 275, 100, 200)
> > e.Graphics.DrawLine(pentje, 100, 200, 25, 150)
> > e.Graphics.DrawLine(pentje, 25, 150, 100, 100)
> > 'kleinere ster
> > e.Graphics.DrawLine(pentje, 100, 100, 150, 50)
> > e.Graphics.DrawLine(pentje, 150, 50, 200, 100)
> > e.Graphics.DrawLine(pentje, 200, 100, 250, 150)
> > e.Graphics.DrawLine(pentje, 250, 150, 200, 200)
> > e.Graphics.DrawLine(pentje, 200, 200, 150, 250)
> > e.Graphics.DrawLine(pentje, 150, 250, 100, 200)
> > e.Graphics.DrawLine(pentje, 100, 200, 50, 150)
> > e.Graphics.DrawLine(pentje, 50, 150, 100, 100)
> > 'kleinste ster
> > e.Graphics.DrawLine(pentje, 100, 100, 150, 75)
> > e.Graphics.DrawLine(pentje, 150, 75, 200, 100)
> > e.Graphics.DrawLine(pentje, 200, 100, 225, 150)
> > e.Graphics.DrawLine(pentje, 225, 150, 200, 200)
> > e.Graphics.DrawLine(pentje, 200, 200, 150, 225)
> > e.Graphics.DrawLine(pentje, 150, 225, 100, 200)
> > e.Graphics.DrawLine(pentje, 100, 200, 75, 150)
> > e.Graphics.DrawLine(pentje, 75, 150, 100, 100)
> >
> >
> > Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As
> System.EventArgs)
> > Handles Timer1.Tick
> > hoek += 3
> > If hoek > 359 Then
> > hoek = 0
> > End If
> > Invalidate()
> > End Sub
> >
> >
>
>



Relevant Pages

  • Re: rotate drawing with matrix
    ... Find great Windows Forms articles in Windows Forms Tips and Tricks ... > I got the following piece of code which draws a square with stars round ... > Private brush As New SolidBrush ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Zero Width Pen Draws through clipped region...
    ... Find great Windows Forms articles in Windows Forms Tips and Tricks ... Exclude the rectangle from the graphics clip region. ... IF you use a pen that is more than one pixel the clipping works ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Partial zooming using transform
    ... Find great Windows Forms articles in Windows Forms Tips and Tricks ... Is there any "good way" of figuring out the dimensoions of the transformed image to get the size of the border I need to draw? ... the "object" will be a square or a slice of pixels with its own individual zoom and transform. ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Scrolling question
    ... Find great Windows Forms articles in Windows Forms Tips and Tricks ... protected override void OnPaint ... > to scoll just fine, but at least for me, the Sine wave will not scroll ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Rotate ellipse around center
    ... Find great Windows Forms articles in Windows Forms Tips and Tricks ... private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs ... > ellipse what so erver. ...
    (microsoft.public.dotnet.framework.drawing)

Quantcast