I've been going in circles trying to figure out how to incorporate a dial control into a Windows form (without having to purchase a third party solution). From the research I've done, it appears I need microsoft.toolkit.uwp.ui.controls. I attempted to install version 6.1.1 (from .nupkg) but receive the following installation error: "Could not install package 'Microsoft.Toolkit.Uwp.UI.Controls 6.1.1'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.7.2', but the package does not contain any assembly references or content files that are compatible with that framework." Any guidance/help will be appreciated.
Asked
Active
Viewed 620 times
0
-
1[Arc graphic quality](https://stackoverflow.com/a/54139910/7444103). Very *raw* design (*style* was not the point), but the base functionality is there. You're probably more interested in the notes. – Jimi Nov 05 '20 at 19:46
-
I googles "dial gauge in .net" and got several hits for free ones. – Mary Nov 09 '20 at 01:32
-
Thanks for your feedback Jimi/Mary. I did Google search for the same thing. The 'free' solutions are a bit misleading. They end up be free trials. I will try Jimi's suggestion. – Jeff S Nov 10 '20 at 13:00
1 Answers
1
Thank you Jimi. The link (Arc graphic quality) worked like a charm. I needed to do a little tweaking to get this to work with VB, but it works. I've attached the VB code.`
Imports System.Drawing.Drawing2D
Public Class Form1
Dim GaugeValue As Single = 75 'move the needle with this value (0 - 100 percent)
Dim GaugeSweepAngle As Single = 270
Dim GaugeStartAngle As Single = 135
Private Sub Canvas_Paint(sender As Object, e As PaintEventArgs) Handles Canvas.Paint
Dim canvas As New Control
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
Dim outerRectangle = New Rectangle(10, 10, 180, 180)
Dim innerRectangle = New Rectangle(30, 30, 140, 140)
Dim blendRectangle = New Rectangle(10, 10, 180, 160)
Dim innerCenter = New PointF(outerRectangle.Left + (outerRectangle.Width / 2), outerRectangle.Top + (outerRectangle.Height / 2))
Dim gaugeLength = (outerRectangle.Width / 2) - 2
Using Path = New GraphicsPath
Path.AddPie(outerRectangle, GaugeStartAngle, GaugeSweepAngle)
Path.AddPie(innerRectangle, GaugeStartAngle, GaugeSweepAngle)
innerRectangle.Inflate(-1, -1)
Using pen = New Pen(Color.Black, 3.0F)
Using backgroundbrush = New SolidBrush(canvas.BackColor)
Using gradientBrush = New LinearGradientBrush(blendRectangle, Color.Green, Color.Red, LinearGradientMode.ForwardDiagonal)
Dim blend = New Blend
Dim factors(0.0, 0.0, 0.1, 0.3, 0.7, 1.0)
Dim positions(0.0, 0.2, 0.4, 0.6, 0.8, 1.0)
gradientBrush.Blend = blend
e.Graphics.FillPath(gradientBrush, Path)
e.Graphics.DrawPath(pen, Path)
e.Graphics.FillEllipse(backgroundbrush, innerRectangle)
Using format = New StringFormat
format.Alignment = StringAlignment.Center
format.LineAlignment = StringAlignment.Center
innerRectangle.Location = New Point(innerRectangle.X, innerRectangle.Y + canvas.Font.Height)
e.Graphics.DrawString(GaugeValue.ToString() + "%", canvas.Font, Brushes.Black, innerRectangle, format)
Using mx = New Matrix
mx.RotateAt(GaugeStartAngle + 90 + (GaugeValue * (GaugeSweepAngle / 100)), innerCenter)
e.Graphics.Transform = mx
e.Graphics.DrawLine(pen, innerCenter, New PointF(innerCenter.X, innerCenter.Y - gaugeLength))
e.Graphics.ResetTransform()
End Using
End Using
End Using
End Using
End Using
End Using
End Sub
End Class`.

Jeff S
- 21
- 3