Scale GraphicsPaths
Posted
by serhio
on Stack Overflow
See other posts from Stack Overflow
or by serhio
Published on 2010-06-17T13:12:02Z
Indexed on
2010/06/17
13:23 UTC
Read the original article
Hit count: 256
In a form I draw a graph. This graph has some distinct paths that should have differently drawn. Say AxesPath, SalesPath, CostsPath etc...
When I resize the form need I to scale every of components Paths?
Take an example:
Imports System.Drawing.Drawing2D
Public Class Form1
Dim lineOne As GraphicsPath
Dim lineTwo As GraphicsPath
Dim allPaths As GraphicsPath
Dim initSize As Size
Public Sub New()
' This call is required by the designer. '
InitializeComponent()
initSize = Me.Size
lineOne = New GraphicsPath()
lineTwo = New GraphicsPath()
lineOne.AddLine(20.0F, 20.0F, Me.initSize.Width - 20.0F, 20.0F)
lineTwo.AddLine(0.1F, 10.0F, Me.initSize.Width - 20.0F, _
Me.initSize.Height - 0.5F)
allPaths = New GraphicsPath()
allPaths.AddPath(lineOne, False)
allPaths.AddPath(lineTwo, False)
Me.ResizeRedraw = True
End Sub
Protected Overrides Sub OnResize(ByVal e As System.EventArgs)
MyBase.OnResize(e)
Dim m As New Matrix
m.Scale(Me.Width / initSize.Width, Me.Height / initSize.Height)
allPaths.Transform(m)
initSize = Me.Size
End Sub
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
MyBase.OnPaint(e)
' WORKS '
' e.Graphics.DrawPath(Pens.GreenYellow, allPaths) '
' DOES NOT WORK! '
e.Graphics.DrawPath(Pens.DarkGoldenrod, lineOne)
e.Graphics.DrawPath(Pens.DarkMagenta, lineTwo)
End Sub
End Class
© Stack Overflow or respective owner