public class barom { System.Drawing.Graphics zona_des; System.Drawing.Bitmap img; Graphics g; System.Drawing.Pen creion_g = new System.Drawing.Pen(System.Drawing.Color.Blue); System.Drawing.Pen creion_g2 = new System.Drawing.Pen(System.Drawing.Color.Blue, 2); System.Drawing.Pen creion_g10 = new System.Drawing.Pen(System.Drawing.Color.LightBlue, 12); System.Drawing.Pen creion_r = new System.Drawing.Pen(System.Drawing.Color.Red); System.Drawing.Pen creion_r2 = new System.Drawing.Pen(System.Drawing.Color.Red, 2); System.Drawing.Pen creion_r10 = new System.Drawing.Pen(System.Drawing.Color.Red, 12); System.Drawing.Font font_arial = new System.Drawing.Font("Arial", 10, FontStyle.Bold); System.Drawing.Font font_arial2 = new System.Drawing.Font("Arial", 16, FontStyle.Bold); System.Drawing.SolidBrush pens_a = new System.Drawing.SolidBrush(System.Drawing.Color.Blue); System.Drawing.SolidBrush pens_r = new System.Drawing.SolidBrush(System.Drawing.Color.Red); System.Drawing.SolidBrush pens_rad = new System.Drawing.SolidBrush(System.Drawing.Color.White); int x0; // pozitia pe x a instrumentului int y0; // pozitia pe y a instrumentului int wd; // latimea int alfa_st; // unghiul de inceput a cadranului in grade(sens direct) int alfa_w; // marimea cadranului in grade int gd; // grade pe diviziune double vmin; // valoarea minima double vmax; // valoarea maxima string um; // unitatea de masura public barom(System.Drawing.Graphics desen, int x, int y, int wi, int gr_st, int gr_w, int gr_d, double vmn, double vmx, string u_m) { zona_des = desen; // desenul x0 = x; // pozitia pe x a instrumentului y0 = y; // pozitia pe y a instrumentului wd = wi; // latimea alfa_st = gr_st; // unghiul de inceput a cadranului in grade(sens direct) alfa_w = gr_w; // marimea cadranului in grade gd = gr_d; // grade pe diviziune vmin = vmn; // valoarea minima vmax = vmx; // valoarea maxima um = u_m; // unitatea de masura } public void setval(double val) { int x1, x2, xt, y1, y2, yt; int xc = wd / 2; int yc = wd / 2; int raza = (wd - wd / 3) / 2; int sd = 0; // semafor (diviziune cu text sau fara text) int nrd = 0; // nr diviziuni double val_c = val; // valoarea curenta double val_gr; // valoarea de afisat in grade double val_a = vmin; // valori afisate de pe cadran double alfa_r = 0; // unghi in radiani double alfa_gr = 0; // unghi in grade int lt = wd / 12; // valoare distantier img = new Bitmap(wd + 2, wd + 20, zona_des); g = Graphics.FromImage(img); // sterg continutul imaginii //g.FillEllipse(pens_rad, 0, 0, wd+2, wd+2); g.FillRectangle(pens_rad, 0, 0, wd + 2, wd + 2); // desenez arc fundal g.DrawArc(creion_g10, 2 * lt, 2 * lt, wd - 4 * lt, wd - 4 * lt, alfa_st, alfa_w); g.DrawArc(creion_r10, 2 * lt, 2 * lt, wd - 4 * lt, wd - 4 * lt, alfa_st + 4 * alfa_w / 5, alfa_w / 5); // desenez cerc origine g.FillEllipse(pens_a, (wd - lt) / 2, (wd - lt) / 2, lt, lt); g.DrawEllipse(creion_r, (wd - lt) / 2, (wd - lt) / 2, lt, lt); g.DrawArc(creion_r, (wd - lt / 2) / 2, (wd - lt / 2) / 2, lt / 2, lt / 2, 0, 360); // desenez gradatii si text alfa_r = 0; alfa_gr = alfa_st; // unghiul start in grade while (alfa_gr <= alfa_st + alfa_w) { alfa_r = Math.PI * (360 - alfa_gr) / 180;// unghiul in radiani x1 = xc + Convert.ToInt32((wd / 2 - lt * 3 / 2) * Math.Cos(alfa_r)); y1 = yc - Convert.ToInt32((wd / 2 - lt * 3 / 2) * Math.Sin(alfa_r)); x2 = xc + Convert.ToInt32((wd / 2 - 3 * lt) * Math.Cos(alfa_r)); y2 = yc - Convert.ToInt32((wd / 2 - 3 * lt) * Math.Sin(alfa_r)); xt = xc - 10 + Convert.ToInt32((wd / 2 - lt) * Math.Cos(alfa_r)); yt = yc - 10 - Convert.ToInt32((wd / 2 - lt) * Math.Sin(alfa_r)); if (sd == 0) { if (wd > 100) g.DrawString(System.Math.Round(val_a, 2).ToString(), font_arial, pens_a, xt, yt); //val_a = val_a + (vmax - vmin) / ((alfa_w / (2 * gd))); sd = 1; if (alfa_gr > (alfa_st + 4 * alfa_w / 5)) g.DrawLine(creion_g2, x1, y1, x2, y2); else g.DrawLine(creion_g2, x1, y1, x2, y2); } else { if (alfa_gr > (alfa_st + 4 * alfa_w / 5)) g.DrawLine(creion_g, x1, y1, x2, y2); else g.DrawLine(creion_g, x1, y1, x2, y2); sd = 0; } alfa_gr += gd; nrd++; val_a = vmin + nrd * (vmax - vmin) / Convert.ToDouble(alfa_w / gd); } // desenez ac indicator // scalare val_gr = alfa_st + Convert.ToInt32(alfa_w * (val_c - vmin) / (vmax - vmin)); alfa_r = Math.PI * (360 - val_gr) / 180; // unghiul in radiani int x = xc + Convert.ToInt32((wd / 2 - lt) * Math.Cos(alfa_r)); int y = yc - Convert.ToInt32((wd / 2 - lt) * Math.Sin(alfa_r)); g.DrawLine(creion_r, xc, yc, x, y); // valoare si um if (wd > 100) g.DrawString(Math.Round(val, 2).ToString(), font_arial2, pens_r, wd / 2 - lt * 3 / 4, wd / 2 + lt); else g.DrawString(Math.Round(val, 2).ToString(), font_arial, pens_r, wd / 2 - lt * 3 / 4, wd / 2 + lt * 2 / 3); if (wd > 100) g.DrawString(um, font_arial, pens_a, Convert.ToInt32(wd / 2 - lt * 2 / 3), Convert.ToInt32(4 * lt)); else g.DrawString(um, font_arial, pens_a, Convert.ToInt32(wd / 2 - lt), Convert.ToInt32(4 * lt)); // desenez cerc exterior // g.DrawArc(creion_g, 0, 0, wd , wd , alfa_st, alfa_w); g.DrawArc(creion_g, 0, 0, wd, wd, 0, 360); // plasez imaginea finala zona_des.DrawImage(img, x0, y0); } }