public class turom
    {
        System.Drawing.Graphics zona_des;
        System.Drawing.Bitmap img;
        Graphics g;
        System.Drawing.Pen creion_g = new System.Drawing.Pen(System.Drawing.Color.LightGreen);
        System.Drawing.Pen creion_g2 = new System.Drawing.Pen(System.Drawing.Color.LightGreen, 3);
        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.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.Yellow);
        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.Black);
        int x0;			// pozitia pe x a instrumentului
        int y0;			// pozitia pe y a instrumentului
        int wd;	    		// latimea
        int alfa_st;			// unghiul de inceput a cadranulu in grade(sens direct)
        int alfa_w;	    		// marimea cadranului in grade
        double vmin;			// valoarea minima
        double vmax;			// valoarea maxima
        int gd; 	    		// grade pe diviziune
        string um;      		// unitatea de masura

        public turom(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;
            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 de afisat
            int val_gr;             	// valoarea de afisat in grade
            double val_a = vmin;    	// valori afisate de pe cadran
            double alfa_r = 0;	 	// unghi in radiani
            int alfa_gr = 0;		// unghi in grade
            int lt = wd / 12;           	// valoare distantier
            img = new Bitmap(wd + 2, wd + 2, 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 gradatii si text

            alfa_r = 0;
            alfa_gr = alfa_st;  // unghiul start in grade
            while (alfa_gr <= alfa_st + alfa_w)
            {
                alfa_r = 2 * Math.PI * (360 - alfa_gr) / 360;// unghiul in radiani
                x1 = Convert.ToInt32(xc + (wd / 2) * Math.Cos(alfa_r));
                y1 = Convert.ToInt32(yc - (wd / 2) * Math.Sin(alfa_r));
                x2 = xc + Convert.ToInt32((wd / 2 - lt) * Math.Cos(alfa_r));
                y2 = yc - Convert.ToInt32((wd / 2 - lt) * Math.Sin(alfa_r));
                xt = xc - lt / 2 + Convert.ToInt32((raza) * Math.Cos(alfa_r));
                yt = yc - 10 - Convert.ToInt32((raza) * Math.Sin(alfa_r));
                if (sd == 0)
                {
                    if (wd > 100)
                        g.DrawString(Math.Round(val_a, 2).ToString(), font_arial, pens_a, xt, yt);
                    sd = 1;
                    if (alfa_gr > (alfa_st + 4 * alfa_w / 5))
                        g.DrawLine(creion_r2, 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_r, 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 = Convert.ToInt32(alfa_st + alfa_w * (val_c - vmin) / (vmax - vmin));
            alfa_r = 2 * Math.PI * (360 - val_gr) / 360;// unghiul in radiani
            int x = xc + Convert.ToInt32((wd / 2) * Math.Cos(alfa_r));
            int y = yc - Convert.ToInt32((wd / 2) * Math.Sin(alfa_r));
            g.DrawLine(creion_g, 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 * 2 / 3);
            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_arial2, pens_a, Convert.ToInt32(wd / 2 - lt), 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_r, 0, 0, wd, wd, alfa_st + 4 * alfa_w / 5, alfa_w / 5);

            // desenez cerc origine
            g.DrawArc(creion_r, (wd - lt / 2) / 2, (wd - lt / 2) / 2, lt / 2, lt / 2, 0, 360);

            // plasez imaginea finala
            zona_des.DrawImage(img, x0, y0);
        }
    }