1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace WinFormsApplicationArc
{
public partial class Form4 : Form
{
public Form4()
{
InitializeComponent();
}
private void DrawRays(Graphics GR)
{
// Create a GraphicsPath object.
GraphicsPath myPath = new GraphicsPath();
Rectangle R = new Rectangle(50, 50, 200, 200);
//rappel: nb de rayon 18 sur 180 degre(180 =>PI)
GR.DrawArc(Pens.Gray, R, -90, +180);
double RadiusLen = R.Width / 2;
PointF CenterRect = new Point(R.X+R.Width/2, R.Y+R.Height / 2);
double dx = Math.PI / 18f;
double angle = 0.0;
for (int i = 0; i < 19; i++)
{
double X = CenterRect.X + RadiusLen * Math.Sin(angle);
double Y = CenterRect.Y + RadiusLen * Math.Cos(angle);
PointF vertex = new PointF((float)X, (float)Y);
GR.DrawLine(Pens.Gray, CenterRect, vertex);
angle =angle+ dx;
}
}
private void Form4_Paint(object sender, PaintEventArgs e)
{
Graphics GR = e.Graphics;
DrawRays(GR);
}
}
// ton code
//Point P0 = new Point(0, R.Height / 2);
//double Pi36 = (Math.PI / 36f);
//double Pi2 = (Math.PI / 2f);
//for (i = 0; i < 19; i++)
//{
// double A = Pi2 + (Pi36 * i);
// double Y = RadiusLen * Math.Cos(A);
// double X = RadiusLen * Math.Sin(A);
// PointF P1 = new PointF((float)X, (float)Y);
// GR.DrawLine(Pens.Gray, P0, P1);
} |
Partager