Quantcast
Channel: VBForums - WPF, WCF, WF
Viewing all articles
Browse latest Browse all 256

WinForm Code to WPF

$
0
0
I have the following code which works in WinForms but I need to redo this in WPF.

Can someone either please help me get started or rewrite this for WPF.

WPF has a Image not a picturebox. Exactly what else is different and where do I start in WPF?
Code:

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        myMethod(78.5, PictureBox1)
    End Sub

    Private Sub myMethod(ByVal PP As Single, ByVal PB As PictureBox)

        PB.BackColor = Color.Transparent

        'Do your drawing here
        Dim img As New Bitmap(PB.Width, PB.Height)

        Dim gr As Graphics = Graphics.FromImage(img)

        gr.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
        gr.Clear(Color.Transparent)

        Dim rect As Rectangle = PictureBox1.ClientRectangle
        rect.Inflate(-10, -10) 'margin of outer circle

        Dim startAngle As Single = 0
        Dim sweepAngle As Single = CSng(PP / 100 * 360)

        'draw the pie
        gr.FillPie(Brushes.AliceBlue, rect, startAngle, sweepAngle)

        'draw the centre circle
        rect.Inflate(-5, -5) 'doughnut thickness
        gr.FillEllipse(Brushes.Black, rect)

        'draw the value text
        Dim str As String = (PP / 100).ToString("P1")

        Using fnt As New Font(Me.Font.FontFamily, 30)
            Using sf As New StringFormat With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center}
                gr.DrawString(str, fnt, Brushes.White, rect, sf)
            End Using
        End Using

        Using sfnt As New Font(Me.Font.FontFamily, 12)
            Using sf As New StringFormat With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Near}
                gr.DrawString("Cars", sfnt, Brushes.White, rect, sf)
            End Using
        End Using

        PB.Image = img
    End Sub

End Class


Viewing all articles
Browse latest Browse all 256

Trending Articles