Example #1
0
        private int GetLabelWidth(System.Windows.Forms.Label label)
        {
            Graphics graphics = label.CreateGraphics();
            SizeF sizeLabel = graphics.MeasureString(label.Text, label.Font);
            graphics.Dispose();

            return (int)sizeLabel.Width + (m_nBorder << 2);
        }
Example #2
0
 public DrawingClass(System.Windows.Forms.Control Control)
 {
     CanvasControl = Control.CreateGraphics();
       _CanvasImage = new Bitmap(Control.Width, Control.Height);
       I2 = Control.Width;
       J2 = Control.Height;
       _CanvasLogics = Graphics.FromImage(_CanvasImage);
 }
Example #3
0
 /// <summary>
 /// Returns a bitmap of the current form.
 /// </summary>
 /// <returns>Returns a bitmap of the current form</returns>
 public static Bitmap ApplicationThumbnail(System.Windows.Forms.Form form)
 {
     Graphics myGraphics = form.CreateGraphics();
     Size s = form.Size;
     Bitmap memoryImage = new Bitmap(s.Width, s.Height, myGraphics);
     Graphics memoryGraphics = Graphics.FromImage(memoryImage);
     memoryGraphics.CopyFromScreen(form.Location.X, form.Location.Y, 0, 0, s);
     return memoryImage;
 }
Example #4
0
        public static void SetBarStartLeft(string rowText, Font rowTextFont,int barStartLeft, System.Windows.Forms.Control ths)
        {
            Graphics gfx = ths.CreateGraphics();
            int length = (int) gfx.MeasureString(rowText, rowTextFont, 500).Width;

            if (length > barStartLeft)
            {
                barStartLeft = length;
            }
        }
Example #5
0
 public static PointF GetDPIScaling(System.Windows.Forms.Form FormUse)
 {
     float dpiX, dpiY;
     Graphics graphics = FormUse.CreateGraphics();
     dpiX = graphics.DpiX;
     dpiY = graphics.DpiY;
     PointF BuildScale = new PointF((float)dpiX/96,(float)dpiY/96);
     if(!ScaleMapping.ContainsKey(FormUse))
     {
         ScaleMapping.Add(FormUse,BuildScale);
     }
     return BuildScale;
 }
 public static void GetLargestTextExtent(System.Windows.Forms.ComboBox cbo, ref int largestWidth)
 {
     int maxLen = -1;
     if (cbo.Items.Count >= 1)
     {
         using (Graphics g = cbo.CreateGraphics())
         {
             int vertScrollBarWidth = 0;
             if (cbo.Items.Count > cbo.MaxDropDownItems)
             {
                 vertScrollBarWidth = SystemInformation.VerticalScrollBarWidth;
             }
             for (int nLoopCnt = 0; nLoopCnt < cbo.Items.Count; nLoopCnt++)
             {
                 int newWidth = (int)g.MeasureString(cbo.Items[nLoopCnt].ToString(), cbo.Font).Width + vertScrollBarWidth;
                 if (newWidth > maxLen)
                 {
                     maxLen = newWidth;
                 }
             }
         }
     }
     largestWidth = maxLen;
 }
Example #7
0
        public void MearseMouseDown(System.Drawing.Point mousePosition, System.Windows.Forms.Control mapControl)
        {
            if (this._graphics == null)
            {
                this._mapControl = mapControl;
                this._graphics = mapControl.CreateGraphics();
                this._measureLine = new GraphicsPath();
            }

            this._graphics.FillRectangle(new SolidBrush(Color.Blue), new Rectangle(mousePosition.X - 3, mousePosition.Y - 3, 6, 6));

            if (this._measureLine.PointCount == 0 && this._startDraw == false)
            {
                this._curPoint = this._prePoint = mousePosition;
                this._startDraw = true;
            }
            else
            {
                this._prePoint = this._curPoint;
                this._curPoint = mousePosition;
                this._measureLine.AddLine(this._prePoint, this._curPoint);
                this._graphics.DrawPath(new System.Drawing.Pen(Color.Blue, 4), this._measureLine);
            }
        }
        public static void drawMap(MappingFSM mapFSM, System.Windows.Forms.Panel panel)
        {
            int xdim = mapFSM.MapDim;
            int ydim = mapFSM.MapDim;

            int mpanelxdim = panel.Width;
            int mpanelydim = panel.Height;

            Graphics mg = panel.CreateGraphics();

            mg.Clear(System.Drawing.Color.White);
            // now calculating cell width and height
            int cellwidth = (int)(mpanelxdim / xdim);
            int cellheight = (int)(mpanelydim / ydim);
            // cell height-width done

            // now drawing maze (with robot)
            int i, j;
            for (i = 0; i < ydim; i++)
                for (j = 0; j < xdim; j++)
                {
                    int x1, y1, x2 = 0, y2 = 0;
                    x1 = j * cellwidth;
                    y1 = i * cellheight;
                    if (mapFSM.Map[i][j] != MappingFSM.cellVOID)
                    {
                        SolidBrush bluebrush = new SolidBrush(mapFSM.Map[i][j] == MappingFSM.cellBLOCK ? Color.Blue : Color.Gray);
                        System.Drawing.Pen blackpen = new Pen(System.Drawing.Color.Black);
                        mg.FillRectangle(bluebrush, x1, y1, cellwidth, cellheight);
                        mg.DrawRectangle(blackpen, x1, y1, cellwidth, cellheight);
                        blackpen.Dispose();
                        bluebrush.Dispose();
                    }

                }

            // now drawing the movile robot
            MappingFSM.drawRobot(mapFSM, mg, mapFSM.jpos, mapFSM.ipos, mapFSM.orientation,
                                 panel, Color.Yellow);
            // now drawing the other robot (if any)
            if (mapFSM.browsingFSM != null)
                MappingFSM.drawRobot(mapFSM, mg, mapFSM.browsingFSM.jpos, mapFSM.browsingFSM.ipos,
                                    mapFSM.browsingFSM.orientation, panel, Color.Green);
        }
Example #9
0
            public static Image GetControlScreenshot(System.Windows.Forms.Control control)
            {
                object x = new object();
                Bitmap bitmap = null;

                lock (control)
                {
                    if (control == null || control.Handle == IntPtr.Zero)
                        return (Image)bitmap;

                    if (control.Width < 1 || control.Height < 1) return (Image)bitmap;

                    if (bitmap != null)
                        bitmap.Dispose();

                    // preparing the bitmap.
                    bitmap = new Bitmap(control.Width, control.Height);

                    bitmap = GetImage(control.CreateGraphics(), control.Width, control.Height, 0);
                }

                return (Image)bitmap;
            }
Example #10
0
 /// <summary>
 /// Gets the graphics object from the given control
 /// </summary>
 /// <param name="control">Control to obtain the graphics from</param>
 /// <returns>A graphics object with the control's characteristics</returns>
 public Graphics GetGraphics(System.Windows.Forms.Control control)
 {
     Graphics graphic;
     if (control.Visible)
     {
         graphic = control.CreateGraphics();
         SetColor(graphic, control.ForeColor);
         SetFont(graphic, control.Font);
     }
     else
     {
         graphic = null;
     }
     return graphic;
 }
Example #11
0
 public static void GetRefControl(System.Windows.Forms.Control Control)
 {
     Control.CreateGraphics();
 }
Example #12
0
 /// <summary>
 /// Create a graphic object from the current control
 /// </summary>
 /// <param name="control"></param>
 public MeasureHelper(System.Windows.Forms.Control control)
 {
     mGraphics = control.CreateGraphics();
     mDisposeObj = true;
 }
Example #13
0
 /// <summary>
 /// Blocks UI blocks
 /// </summary>
 /// <param name="bp">The picture box which the changes will be applied to</param>
 /// <param name="p">A point in the bitmap to extract the line it has been linked</param>
 /// <param name="auto_update_status">Shoud it automatically update the grid's block status?</param>
 public void Block(System.Windows.Forms.PictureBox pb, Point p, bool force = false, bool auto_update_status = true)
 {
     var bm = (Bitmap)pb.Image;
     if (!force && (p.X == bm.Width - 1 || p.Y == bm.Height - 1)) return;
     Color c = bm.GetPixel(p.X, p.Y);
     if (c.A != 255) return;
     using (Graphics g = pb.CreateGraphics())
     {
         foreach (var line in this.__get_line_location(bm, p))
         {
             if (!this.Gridlines.Contains(line))
             {
                 Pen pen = new Pen(Color.Black, 10);
                 this.Gridlines.Add(line, 1);
                 g.DrawLine(pen, line.Key, line.Value);
                 if (auto_update_status)
                     this.__update_block_status(line, BlockStatus.BLOCKED);
             }
         }
     }
 }
Example #14
0
    /// <summary>
    /// Dessiner l'automate dans un Panel.
    /// </summary>
    /// <param name="DrawPanel">Le panel ou on va dessiner l'automate</param>
    /// <param name="fix">La methode de deplacement des etats dans le dessin
    /// true pour des emplacements fixes</param>
    public void Draw(System.Windows.Forms.Panel DrawPanel, bool fix)
    {
        Random Ran = new Random();

        Dessin = DrawPanel.CreateGraphics();
        AutoImage = new Bitmap(DrawPanel.Width, DrawPanel.Height);
        grImage = Graphics.FromImage(AutoImage);

        SolidBrush pinceau = new SolidBrush(Color.Blue);
        Pen myPen = new Pen(Color.Blue, 2);
        Font myfont = new Font("Verdana", 8, FontStyle.Bold);

        DrawPanel.Refresh();
        //Dessin.PixelOffsetMode = PixelOffsetMode.HighQuality;
        Dessin.SmoothingMode = SmoothingMode.AntiAlias;
        grImage.SmoothingMode = SmoothingMode.AntiAlias;

        Pen inipen = new Pen(Color.Coral, 5);
        inipen.CustomEndCap = new AdjustableArrowCap(3, 3, false);

        if (!DessinChanged)
            if (fix)
            {
                myPointArray = new Point[10];
                int[] TabX = new int[8];
                for (int i = 0; i < 8; i++)
                {
                    TabX[i] = (int)i * ((DrawPanel.Width - 40) / 7);
                }
                int[] TabY = new int[5];
                for (int i = 0; i < 5; i++)
                {
                    TabY[i] = (int)i * ((DrawPanel.Height - 28) / 4);
                }

                #region myPointArray
                myPointArray[0] = new Point(TabX[4], TabY[0]);
                myPointArray[1] = new Point(TabX[0], TabY[2]);
                myPointArray[2] = new Point(TabX[7], TabY[2]);
                myPointArray[3] = new Point(TabX[5], TabY[3]);
                myPointArray[4] = new Point(TabX[5], TabY[1]);
                myPointArray[5] = new Point(TabX[2], TabY[3]);
                myPointArray[6] = new Point(TabX[3], TabY[0]);
                myPointArray[7] = new Point(TabX[4], TabY[4]);
                myPointArray[8] = new Point(TabX[2], TabY[1]);
                myPointArray[9] = new Point(TabX[3], TabY[4]);
                #endregion

            }
            else
            {
                myPointArray = new Point[this.S];
                //les restes sont calcul├ęs
                double alpha = (Math.PI * 2) / this.S;
                for (int i = 0; i < this.S; i++)
                {
                    myPointArray[i] = new Point((int)((Math.Cos((i - 1) * alpha) * (DrawPanel.Width / 2.75)) + DrawPanel.Width / 2.2), (int)((Math.Sin((i - 1) * alpha) * 90) + 100));

                }

            }

        if (this.S > 10)
            DrawPanel.BackColor = Color.Red;
        for (int i = 0; (i < this.S); i++)
        {
            Point p = myPointArray[i];
            Dessin.DrawEllipse(myPen, p.X, p.Y, 30, 30);
            grImage.DrawEllipse(myPen, p.X, p.Y, 30, 30);

            if (this.S0 == i) //etat ititial
            {

                Dessin.DrawLine(inipen, p.X - 40, p.Y + 5, p.X - 10, p.Y + 10);
                grImage.DrawLine(inipen, p.X - 40, p.Y + 5, p.X - 10, p.Y + 10);
            }
            if (this.F.Contains(i)) //etat final
            {
                grImage.DrawEllipse(myPen, p.X + 2, p.Y + 2, 30 - 4, 30 - 4);
                Dessin.DrawEllipse(myPen, p.X + 2, p.Y + 2, 30 - 4, 30 - 4);
            }

            for (int j = 0; (j < this.S) & (j < 10); j++)
            {

                String CsTran = "";
                if (this.getType() != TYPE.Gfa)
                    foreach (char car in this.X)
                    {
                        if (this.getType() == TYPE.Dfa)
                        {
                            if (((Dfa)this).getInstruction(i, car) == j)
                            {
                                CsTran += ((CsTran.Length == 0) ? (car.ToString()) : ("/" + car.ToString()));
                            }
                        }
                        else
                        {
                            if (((Automata)this).getInstruction(i, car).Contains(j))
                            {
                                CsTran += ((CsTran.Length == 0) ? (car.ToString()) : ("/" + car.ToString()));
                            }

                        }

                    }
                else
                    foreach (Object MotObj in ((Gfa)this).Read)
                    {
                        string Mot = MotObj.ToString();
                        if (((Gfa)this).getInstruction(i, Mot).Contains(j))
                        {
                            CsTran += ((CsTran.Length == 0) ? (Mot.ToString()) : ("/" + Mot));
                        }

                    }

                #region //DrawTransition(i, j, CsTran);
                AdjustableArrowCap Fleche = new AdjustableArrowCap(5, 5, true);
                Pen FlechePen = new Pen(Color.Red, 2);
                FlechePen.CustomEndCap = Fleche;
                if (CsTran.Length != 0)       // il existe une transition de Si vers Sj
                {
                    Point p1 = myPointArray[i];
                    Point p2 = myPointArray[j];

                    Point t1 = new Point();
                    Point t2 = new Point();
                    Point t3 = new Point();
                    Point t4 = new Point();

                    /*if (p2.X < p1.X)
                    {
                        t2.X = p1.X;
                        t1.X = p2.X + 30;
                        t3.X = t4.X = ((t1.X + t2.X) / 2) - (20 * i);
                    }
                    else {
                        t2.X = p1.X + 30;
                        t1.X = p2.X;
                        t3.X = t4.X = ((t1.X + t2.X) / 2) + (20 * i);

                    }

                    if (p2.Y < p1.Y)
                    {
                        t2.Y = p1.Y + 15;
                        t1.Y = p2.Y + 15;
                        t3.Y = t4.Y = ((t1.Y + t2.Y) / 2) - (20 * i);
                    }
                    else
                    {
                        t2.Y = p1.Y + 15;
                        t1.Y = p2.Y + 15;
                        t3.Y = t4.Y = ((t1.Y + t2.Y) / 2) + (20 * i);
                    }

                    Dessin.DrawBezier(FlechePen,t1,t3 ,t4,t2);
                     */

                    if (p2 != p1)
                    {

                        Dessin.DrawBezier(FlechePen, p1.X + ((p1.X > p2.X) ? (0) : (30)), p1.Y + 10 + (2 * i), ((p2.X + p1.X) / 2), ((6 * p1.Y + p2.Y) / 7) - 40 + Ran.Next(80), (p2.X + p1.X) / 2, ((6 * p1.Y + p2.Y) / 7) - 40 + Ran.Next(80), p2.X + ((p1.X > p2.X) ? (30) : (0)), p2.Y + 10 + +(2 * i));
                        Dessin.DrawString(CsTran, myfont, pinceau, ((p2.X + p1.X) / 2), (4 * p1.Y + p2.Y) / 5);
                        grImage.DrawBezier(FlechePen, p1.X + ((p1.X > p2.X) ? (0) : (30)), p1.Y + 10 + (2 * i), ((p2.X + p1.X) / 2), ((6 * p1.Y + p2.Y) / 7) - 40 + Ran.Next(80), (p2.X + p1.X) / 2, ((6 * p1.Y + p2.Y) / 7) - 40 + Ran.Next(80), p2.X + ((p1.X > p2.X) ? (30) : (0)), p2.Y + 10 + +(2 * i));
                        grImage.DrawString(CsTran, myfont, pinceau, ((p2.X + p1.X) / 2), (4 * p1.Y + p2.Y) / 5);

                    }
                    else //Si -> Si
                    {

                        Dessin.DrawBezier(FlechePen, p1.X, p1.Y + 15, p1.X + 2, p1.Y + 60, p1.X + 25, p1.Y + 60, p1.X + 30, p1.Y + 15);
                        Dessin.DrawString(CsTran, myfont, pinceau, p1.X + 15, p1.Y + 30);

                        grImage.DrawBezier(FlechePen, p1.X, p1.Y + 15, p1.X + 2, p1.Y + 60, p1.X + 25, p1.Y + 60, p1.X + 30, p1.Y + 15);
                        grImage.DrawString(CsTran, myfont, pinceau, p1.X + 15, p1.Y + 30);
                    }

                }
                SolidBrush Fill = new SolidBrush(Color.White);
                Dessin.FillEllipse(Fill, p.X + 3, p.Y + 3, 30 - 6, 30 - 6);
                Dessin.DrawString("S" + i, myfont, pinceau, (p.X + 5), (p.Y + 8));

                grImage.FillEllipse(Fill, p.X + 3, p.Y + 3, 30 - 6, 30 - 6);
                grImage.DrawString("S" + i, myfont, pinceau, (p.X + 5), (p.Y + 8));

                #endregion
            }

        }

        //DrawPanel.Refresh();
    }
Example #15
0
 // Needs to be called once to know associated object
 public void SetDrawDestination(ref System.Windows.Forms.PictureBox obj)
 {
     Video = obj.CreateGraphics();
     VBlank();
 }
Example #16
0
 public static int MeasureTextWidth(System.Windows.Forms.Control c, string text)
 {
     if (c == null)
     { return -1; }
     using (System.Drawing.Graphics g = c.CreateGraphics())
     {
         return (int)Math.Ceiling(g.MeasureString(text, c.Font).Width);
     }
 }
        // draw the 16x16 abstraction
        public void drawAbstraction(System.Windows.Forms.Panel panel)
        {
            int AbstractedFrameWidth = panel.Width;
            int AbstractedFrameHeight = panel.Height;
            Graphics gr = panel.CreateGraphics();
            gr.Clear(Color.White);
            int line, col, i, j;
            int resolutionX = AbstractedFrameWidth / ABSTRACTION_FRAME_WIDTH;
            int resolutionY = AbstractedFrameHeight / ABSTRACTION_FRAME_HEIGHT;
            for (line = 0; line < ABSTRACTION_FRAME_HEIGHT; line++)
                for (i = 0; i < resolutionY; i++)
                    for (col = 0; col < ABSTRACTION_FRAME_WIDTH; col++)
                        for (j = 0; j < resolutionX; j++)
                        {
                            System.Drawing.Pen pen = new Pen(Color.FromArgb(RawAbstraction[(line * ABSTRACTION_FRAME_WIDTH + col) * 3],
                                                                            RawAbstraction[(line * ABSTRACTION_FRAME_WIDTH + col) * 3 + 1],
                                                                            RawAbstraction[(line * ABSTRACTION_FRAME_WIDTH + col) * 3 + 2]
                                                                            )
                                                                            );
                            int y = line * resolutionY + i;
                            int x = col * resolutionX + j;

                            gr.DrawLine(pen, x, y, x + 1, y + 1);
                        }
            flagAbstractionReady = false;
        }
Example #18
0
 /// <summary>
 /// Gets the graphics object from the given control
 /// </summary>
 /// <param name="control">Control to obtain the graphics from</param>
 /// <returns>A graphics object with the control's characteristics</returns>
 public System.Drawing.Graphics GetGraphics(System.Windows.Forms.Control control)
 {
     System.Drawing.Graphics graphic;
     if (control.Visible == true)
     {
         graphic = control.CreateGraphics();
     }
     else
     {
         graphic = null;
     }
     return graphic;
 }
Example #19
0
        public static void WritePiece(int[,] data, System.Windows.Forms.Panel panel)
        {
            System.Drawing.Graphics g = panel.CreateGraphics();
            System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black);

            for (int x = 0; x < 8; x++)
            {
                for (int y = 0; y < 8; y++)
                {
                    if (data[x, y] == 1)
                    {
                        myBrush.Color = Color.Black;
                        g.FillEllipse(myBrush, x * 50 + 2, y * 50 + 2, 45, 45);

                    }
                    else if (data[x, y] == 0)
                    {
                        myBrush.Color = Color.WhiteSmoke;
                        g.FillEllipse(myBrush, x * 50 + 2, y * 50 + 2, 45, 45);

                    }

                }
            }

            myBrush.Dispose();
        }
Example #20
0
        public static void WriteAvailable(int[,] data, System.Windows.Forms.Panel panel)
        {
            System.Drawing.Graphics g = panel.CreateGraphics();
            System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Blue);

            for (int x = 0; x < 8; x++)
            {
                for (int y = 0; y < 8; y++)
                {
                    if (data[x, y] == 1)
                    {
                        g.FillEllipse(myBrush, x * 50 + 25, y * 50 + 25, 5, 5);
                    }

                }
            }

            myBrush.Dispose();
        }