public class binar { Graphics des; System.Drawing.Pen creion; System.Drawing.SolidBrush pens_verde; System.Drawing.SolidBrush pens_rosie; System.Drawing.SolidBrush pens_gri; System.Drawing.Font font_nina; int px0; // pozitia pe x int py0; // pozitia pe y int bit_w; // latimea unui bit int nrb; // numarul de biti int vh; // vertical(v_h=1)/orizontal(v_h=0) int dc; // dreptunghi(d_c=1)/cerc(d_c=0) int rv; // rosu r_v=1, verde r_v=0) int i; public void setval(UInt64 n) { if (rv == 1) pens_verde = pens_rosie; int x = 0, y = 0; x = px0 + bit_w; y = py0 + bit_w; if ((vh == 1) && (dc == 1)) y = py0 + bit_w + bit_w / 4; if (vh == 0) { for (i = nrb - 1; i >= 0; i--) { System.UInt64 bit = ((n >> (nrb - i - 1)) & 1); if (dc == 0) des.DrawEllipse(creion, x - 1, y - 1, bit_w + 2, bit_w + 2); else des.DrawRectangle(creion, x - 1, y - 1, bit_w + 2, bit_w / 2 + 2); if (bit==1) { if (dc == 0) des.FillEllipse(pens_verde, x, y, bit_w, bit_w); else des.FillRectangle(pens_verde, x, y, bit_w, bit_w / 2); } else { if (dc == 0) des.FillEllipse(pens_gri, x, y, bit_w, bit_w); else des.FillRectangle(pens_gri, x, y, bit_w, bit_w / 2); } x += 2 * bit_w; } } if (vh == 1) { for (i = 0; i < nrb; i++) { System.UInt64 bit = ((n >> (nrb - i - 1)) & 1); if (dc == 0) des.DrawEllipse(creion, x - 1, y - 1, bit_w + 2, bit_w + 2); else des.DrawRectangle(creion, x - 1, y - 1, bit_w + 2, bit_w / 2 + 2); if (bit == 1) { if (dc == 0) des.FillEllipse(pens_verde, x, y, bit_w, bit_w); else des.FillRectangle(pens_verde, x, y, bit_w, bit_w / 2); } else { if (dc == 0) des.FillEllipse(pens_gri, x, y, bit_w, bit_w); else des.FillRectangle(pens_gri, x, y, bit_w, bit_w / 2); } y += 2 * bit_w; } } } public void setname(string[] nume_biti) { int x = 0, y = 0; if (vh == 0) { x = px0 + bit_w; y = py0 + bit_w; for (i = nrb - 1; i >= 0; i--) { des.DrawString(nume_biti[i].ToString(), font_nina, pens_rosie, x, y - 2 * bit_w); x += 2 * bit_w; } } if (vh == 1) { x = px0 + 3 * bit_w; y = py0 + 3 * bit_w - bit_w / 4; ; for (i = 0; i < nrb; i++) { des.DrawString(nume_biti[i].ToString(), font_nina, pens_rosie, x, y - 2 * bit_w); y += 2 * bit_w; } } } public binar(Graphics desen, int pozx, int pozy, int w, int nr_biti, int v_h, int d_c,int r_v) { des = desen; creion = new System.Drawing.Pen(System.Drawing.Color.Gray, 2); pens_verde = new System.Drawing.SolidBrush(System.Drawing.Color.Lime); pens_rosie = new System.Drawing.SolidBrush(System.Drawing.Color.Red); pens_gri = new System.Drawing.SolidBrush(System.Drawing.Color.LightGray); font_nina = new System.Drawing.Font("Nina", 12); px0 = pozx; // pozitia pe x py0 = pozy; // pozitia pe y bit_w = w; // latimea unui bit nrb = nr_biti; // numarul de biti vh = v_h; // vertical(v_h=1)/orizontal(v_h=0) dc = d_c; // dreptunghi(d_c=1)/cerc(d_c=0) rv = r_v; // rosu r_v=1, verde r_v=0) } }