G
Guest
Hi All,
I am tying to build a ASP.net 2.0 based web page which displays a Analog
Guage ( 0 to 180 degrees) with an Arrow in the middle.
The application accepts the Percentage as input from a text box and then
generates an image which shows a Arrow pointer dipicting that percentage on
the Arc (or guage).
I am dynamically generating the arcs and the pointer using Draw Pie ( and
Fill pie) and DrawLine methods of the Graphics Class.
But the problem is though the logic is correct, but the drawline is not i
the correct angle. Can you please help my find out where i have gone wrong. I
hae pasted the code, you can run and check how it is working.
Code Below:
*********************************************************
Dim iPercentage As New Integer
iPercentage = Integer.Parse(TextBox1.Text)
Dim arrowAngle As New Integer
'o% is 0 Degrees and 100% is 180 degrees
arrowAngle = Integer.Parse(iPercentage * 1.8)
'for drawing the arcs , using the drw pie method
'****************************************************************
Dim objBitmap As New Bitmap(200, 200)
Dim objGraphic As Graphics = Graphics.FromImage(objBitmap)
Dim blackPen As New Pen(Color.Black, 5)
Dim whiteBrush As New SolidBrush(Color.White)
objGraphic.FillRectangle(whiteBrush, 0, 0, 200, 200)
Dim rect As New RectangleF(0, 0, 200, 200)
objGraphic.DrawPie(Pens.Black, rect, 0, -180)
Dim rect1 As New Rectangle(0, 0, 200, 200)
objGraphic.FillPie(Brushes.Blue, rect1, 0, -180)
rect = New RectangleF(10, 10, 180, 180)
objGraphic.DrawPie(Pens.Black, rect, 0, -180)
rect1 = New Rectangle(10, 10, 180, 180)
objGraphic.FillPie(Brushes.White, rect1, 0, -180)
'to display the arrow with in the Pie Drawn which gives the Guage
Look and feel
' i am getting the Coordinated for the angle found so that the line drawn
is at an angle.
'************************************************
Dim mcos As Integer
Dim msin As Integer
mcos = Math.Cos(arrowAngle) * 100
msin = Math.Sin(arrowAngle) * 100
objGraphic.DrawLine(Pens.Blue, 100, 100, mcos, msin)
Response.ContentType = "image/gif"
objBitmap.Save(Response.OutputStream, ImageFormat.Gif)
objGraphic.Dispose()
*********************************************************
Please Help me out in this.
Regards
Sura
I am tying to build a ASP.net 2.0 based web page which displays a Analog
Guage ( 0 to 180 degrees) with an Arrow in the middle.
The application accepts the Percentage as input from a text box and then
generates an image which shows a Arrow pointer dipicting that percentage on
the Arc (or guage).
I am dynamically generating the arcs and the pointer using Draw Pie ( and
Fill pie) and DrawLine methods of the Graphics Class.
But the problem is though the logic is correct, but the drawline is not i
the correct angle. Can you please help my find out where i have gone wrong. I
hae pasted the code, you can run and check how it is working.
Code Below:
*********************************************************
Dim iPercentage As New Integer
iPercentage = Integer.Parse(TextBox1.Text)
Dim arrowAngle As New Integer
'o% is 0 Degrees and 100% is 180 degrees
arrowAngle = Integer.Parse(iPercentage * 1.8)
'for drawing the arcs , using the drw pie method
'****************************************************************
Dim objBitmap As New Bitmap(200, 200)
Dim objGraphic As Graphics = Graphics.FromImage(objBitmap)
Dim blackPen As New Pen(Color.Black, 5)
Dim whiteBrush As New SolidBrush(Color.White)
objGraphic.FillRectangle(whiteBrush, 0, 0, 200, 200)
Dim rect As New RectangleF(0, 0, 200, 200)
objGraphic.DrawPie(Pens.Black, rect, 0, -180)
Dim rect1 As New Rectangle(0, 0, 200, 200)
objGraphic.FillPie(Brushes.Blue, rect1, 0, -180)
rect = New RectangleF(10, 10, 180, 180)
objGraphic.DrawPie(Pens.Black, rect, 0, -180)
rect1 = New Rectangle(10, 10, 180, 180)
objGraphic.FillPie(Brushes.White, rect1, 0, -180)
'to display the arrow with in the Pie Drawn which gives the Guage
Look and feel
' i am getting the Coordinated for the angle found so that the line drawn
is at an angle.
'************************************************
Dim mcos As Integer
Dim msin As Integer
mcos = Math.Cos(arrowAngle) * 100
msin = Math.Sin(arrowAngle) * 100
objGraphic.DrawLine(Pens.Blue, 100, 100, mcos, msin)
Response.ContentType = "image/gif"
objBitmap.Save(Response.OutputStream, ImageFormat.Gif)
objGraphic.Dispose()
*********************************************************
Please Help me out in this.
Regards
Sura