Пример #1
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog open = new OpenFileDialog();

            open.Filter = "Png files| *.png| jpeg files| *jpg| bitmaps| *bmp";
            if (open.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                try
                {
                    Bitmap pmOp = new Bitmap(open.FileName);
                    //shape.bm = new Bitmap(pmOp.Width, pmOp.Height);
                    //shape.bm = pmOp;
                    //   //Image im = (Image)shape.bm;

                    DrawPanel.Width  = pmOp.Width;
                    DrawPanel.Height = pmOp.Height;
                    Graphics graphics;
                    //DrawPanel.BackgroundImage = shape.bm;
                    graphics = DrawPanel.CreateGraphics();
                    //shape.g = Graphics.FromImage(im);
                    graphics.DrawImage(pmOp, 0, 0, pmOp.Width, pmOp.Height);
                    graphics.Dispose();
                    pmOp.Dispose();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error loading image " + ex.Message);
                }
            }
        }
Пример #2
0
        /* -------------------------------------------------------------------------------
         * Constructor: Form1
         *
         * Use: Constructs a new Dirived Form object.
         *
         * Parameters: none
         * -------------------------------------------------------------------------------*/
        public Form1()
        {
            InitializeComponent();

            //Generate a new graphics object for displaying images
            g = DrawPanel.CreateGraphics();

            //Creates a new bitmap that is the same size as the drawing field, and sets it to all white
            Canvas = new Bitmap(DrawPanel.Size.Width, DrawPanel.Size.Height);
            DrawPanel.DrawToBitmap(Canvas, new Rectangle(0, 0, DrawPanel.Size.Width, DrawPanel.Size.Height));

            //Generate a new graphics object for saving images
            bitmapg = Graphics.FromImage(Canvas);

            //Initialize Variables.
            DrawCurrentColor           = Color.Black;
            DrawBackgroundColor        = Color.White;
            BackgroundButton.BackColor = Color.White;

            RecentFiles.Add(SaveHold1);
            RecentFiles.Add(SaveHold2);
            RecentFiles.Add(SaveHold3);
            RecentFiles.Add(SaveHold4);
            RecentFiles.Add(SaveHold5);
        }
Пример #3
0
        /// <summary>
        /// 开始与暂停
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void StartStopBtn_Click(object sender, EventArgs e)
        {
            if (ViewModule.IsRecording)
            {
                if (writer != null)
                {
                    writer.Close();
                }
                capture.StopRecording();
                if (IsSaveFile.Checked)
                {
                    FileNameContent.Text += "(Saved)";
                }
            }
            else
            {
                if (bufferedGraphics == null)
                {
                    bufferedGraphics = BufferedGraphicsManager.Current.Allocate(DrawPanel.CreateGraphics(), DrawPanel.ClientRectangle);
                }
                if (IsSaveFile.Checked)
                {
                    string filename = Path.GetFileName(Path.GetRandomFileName()) + ".wav";
                    writer = new WaveFileWriter(filename, capture.WaveFormat);
                    FileNameContent.Text = filename;
                }
                capture.StartRecording();
            }

            ViewModule.IsRecording ^= true;
        }
Пример #4
0
        public GameEngine(Form form, int width = 500, int height = 500)
        {
            this.Form = form;
            this.Form.FormBorderStyle = FormBorderStyle.Fixed3D;

            // Double Buffering
            DrawPanel panel = new DrawPanel(width, height);

            Form.Controls.Add(panel);


            // No Resizing
            this.Form.MaximizeBox = false;
            //this.form.MinimizeBox = false;

            this.Form.ClientSize = new Size(width, height); // Size of form

            g            = panel.CreateGraphics();
            worldManager = new WorldManager(this);
            fps          = 0;

            KeyHandler = new KeyHandler(form);

            // Add Closing Event
            form.FormClosing += (sender, args) => Stop();



            ticks = new Dictionary <TickSchedule, List <Action> >();
            foreach (TickSchedule t in Enum.GetValues(typeof(TickSchedule)))
            {
                ticks[t] = new List <Action>();
            }
        }
Пример #5
0
        public void DrawPolyPoints(List <MyPoint> pts)
        {
            try
            {
                int h = 0;
                int xmax = 0, xmin = 0, ymax = 0, ymin = 0;
                FindEdgePoints(pts, ref xmax, ref xmin, ref ymax, ref ymin);
                SysCoord(xmax, xmin, ymax, ymin, ref h);
                PointF[] PolyPts = new PointF[pts.Count];
                for (int i = 0; i < pts.Count; i++)
                {
                    PolyPts[i] = new PointF(Center(pts[i].x, h), Center(-pts[i].y, h));
                }
                using (Graphics g = DrawPanel.CreateGraphics())
                {
                    using (Pen p = new Pen(ColorPoint, SizePoint))
                    {
                        DrawVertexes(g, p, h, pts);
                        p.Color = ColorEdge;
                        p.Brush = new SolidBrush(ColorEdge);
                        p.Width = SizeEdge;

                        g.DrawPolygon(p, PolyPts);
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message + '\n' + '\r' + e.StackTrace, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #6
0
 private void DrawPanel_Paint(object sender, PaintEventArgs e)
 {
     System.Drawing.Pen linepen;
     linepen = new System.Drawing.Pen(System.Drawing.Color.Black);
     System.Drawing.Graphics g = DrawPanel.CreateGraphics();
     g.DrawLine(linepen, 0, DrawPanel.Height / 2, DrawPanel.Width, DrawPanel.Height / 2);
     g.DrawLine(linepen, DrawPanel.Width / 2, 0, DrawPanel.Width / 2, DrawPanel.Height);
 }
Пример #7
0
 public static Color fillColor;      //
 public Form1()
 {
     InitializeComponent();
     primitive = new Pencil(DrawPanel.CreateGraphics());
     p         = new Pen(Color.Black, (float)trackBarThickness.Value);
     fillColor = Color.Black;
     // buttonInvert.Click += MakeWork;
 }
Пример #8
0
 public MainForm()
 {
     InitializeComponent();
     _graphics       = DrawPanel.CreateGraphics();
     StopBtn.Enabled = false;
     SimBackgroundWorker.WorkerSupportsCancellation = true;
     SimBackgroundWorker.WorkerReportsProgress      = true;
 }
Пример #9
0
        private void DrawHangPost()
        {
            Graphics g = DrawPanel.CreateGraphics();
            Pen      p = new Pen(Color.Red, 10);

            g.DrawLine(p, new Point(220, 420), new Point(220, 10));
            g.DrawLine(p, new Point(225, 5), new Point(110, 5));
            g.DrawLine(p, new Point(110, 0), new Point(110, 60));
            RandomWord();
            MakeLabels();
        }
Пример #10
0
        public MainWindow()
        {
            InitializeComponent();
            graphicsDrawPanel = DrawPanel.CreateGraphics();
            Tools             = new List <Button>();
            Tools.Add(PenBrush);
            ShapeCalcToolBox._oldButton = Tools[0];

            Tools.Add(CurveBrush);
            Tools.Add(MovePoint);
        }
Пример #11
0
        private void buttonInvert_Click(object sender, EventArgs e)
        {
            Bitmap   bm       = new Bitmap(DrawPanel.Width, DrawPanel.Height);
            Graphics graphics = Graphics.FromImage(bm);

            System.Drawing.Rectangle rect = DrawPanel.RectangleToScreen(DrawPanel.ClientRectangle);
            graphics.CopyFromScreen(rect.Location, Point.Empty, DrawPanel.Size);
            graphics = DrawPanel.CreateGraphics();
            graphics.DrawImage(Inversion.InvertImage(bm), 0, 0, bm.Width, bm.Height);
            bm.Dispose();
            graphics.Dispose();
        }
Пример #12
0
 private void DrawPanel_Paint(object sender, PaintEventArgs e)
 {
     if (null != CurBitMap)
     {
         lock (TraceLock)
         {
             DrawPanel.CreateGraphics().DrawImageUnscaled(CurBitMap, 0, 0);
         }
     }
     else
     {
         DrawPanel.CreateGraphics().Clear(Color.White);
     }
 }
Пример #13
0
        private void DrawPreviewAutomata()
        {
            if (WindowState == FormWindowState.Minimized)
            {
                return;
            }

            var graph = new AutomataGraph(Automata);

            try
            {
                if (SourceStateIdComboBox.SelectedIndex == -1 || TargetStateIdComboBox.SelectedIndex == -1)
                {
                    return;
                }

                var sourceDrawingState = graph.FindNode(SourceStateIdComboBox.SelectedItem as string) as State;
                var targetDrawingState = graph.FindNode(TargetStateIdComboBox.SelectedItem as string) as State;

                var transition = ConstructTransition(sourceDrawingState.LogicState.Id, targetDrawingState.LogicState.Id);

                var edge = new Edge(sourceDrawingState, targetDrawingState, transition);

                graph.SetupEdge(edge);

                edge.Attr.Color = edge.Label.FontColor = MsaglColor.Blue;

                graph.AddPrecalculatedEdge(edge);

                ErrorLabel.Text = "";
            }
            catch
            {
                ErrorLabel.Text = "A megadott szimbólum nem elérhető az ábécében!";
            }

            var renderer = new GraphRenderer(graph);

            renderer.CalculateLayout();

            using (var graphics = DrawPanel.CreateGraphics())
            {
                graphics.SmoothingMode      = SmoothingMode.HighQuality;
                graphics.TextRenderingHint  = TextRenderingHint.AntiAliasGridFit;
                graphics.CompositingQuality = CompositingQuality.HighQuality;
                graphics.InterpolationMode  = InterpolationMode.HighQualityBicubic;

                renderer.Render(graphics, 0, 0, DrawPanel.Width, DrawPanel.Height);
            }
        }
Пример #14
0
        public Visualizer()
        {
            InitializeComponent();

            _graphics = DrawPanel.CreateGraphics();
            _graphics.SmoothingMode      = SmoothingMode.AntiAlias;
            _graphics.CompositingQuality = CompositingQuality.AssumeLinear;
            _graphics.PixelOffsetMode    = PixelOffsetMode.Default;
            _graphics.TextRenderingHint  = TextRenderingHint.ClearTypeGridFit;
            _graphics.Clear(Color.Black);

            _oscilloscope = new Oscilloscope();

            for (int i = 0; i < _pens.Length; i++)
            {
                _pens[i] = new Pen(Color.FromArgb(i, i, i));
            }

            _fftProvider = new FftProvider(1, FftSize.Fft4096);

            _soundIn = new WasapiLoopbackCapture();
            _soundIn.Initialize();

            var soundInSource = new SoundInSource(_soundIn);
            var singleBlockNotificationStream = new SingleBlockNotificationStream(soundInSource);

            _source = singleBlockNotificationStream.ToWaveSource();

            if (!Directory.Exists("%AppData%/Spectrograph"))
            {
                Directory.CreateDirectory("%AppData%/Spectrograph");
            }

            _writer = new WaveWriter("%AppData%/Spectrograph/loopback.wav", _source.WaveFormat);

            byte[] buffer = new byte[_source.WaveFormat.BytesPerSecond / 2];
            soundInSource.DataAvailable += (s, e) =>
            {
                int read;
                while ((read = _source.Read(buffer, 0, buffer.Length)) > 0)
                {
                    _writer.Write(buffer, 0, read);
                }
            };

            singleBlockNotificationStream.SingleBlockRead += SingleBlockNotificationStreamOnSingleBlockRead;

            _soundIn.Start();
        }
Пример #15
0
        private void DrawPreviewAutomata()
        {
            if (WindowState == FormWindowState.Minimized)
            {
                return;
            }

            var graph = new AutomataGraph(Automata);

            if (Automata.GetState(StateIdTextBox.Text) != null)
            {
                return;
            }

            if (StateIdTextBox.Text.Length > 0)
            {
                var state = new State(ConstructState());

                state.Attr.Color      = MsaglColor.Blue;
                state.Label.FontColor = MsaglColor.Blue;

                var startState = Automata.GetStartState();

                if (state.IsStartState && startState != null)
                {
                    var oldStartState = graph.FindNode(startState.Id) as State;

                    oldStartState.OverrideIsStartState = false;
                }

                graph.SetupState(state);
                graph.AddNode(state);
            }

            var renderer = new GraphRenderer(graph);

            renderer.CalculateLayout();

            using (var graphics = DrawPanel.CreateGraphics())
            {
                graphics.SmoothingMode      = SmoothingMode.HighQuality;
                graphics.TextRenderingHint  = TextRenderingHint.AntiAliasGridFit;
                graphics.CompositingQuality = CompositingQuality.HighQuality;
                graphics.InterpolationMode  = InterpolationMode.HighQualityBicubic;

                renderer.Render(graphics, 0, 0, DrawPanel.Width, DrawPanel.Height);
            }
        }
Пример #16
0
        public Form1()
        {
            InitializeComponent();

            // Создание списка объектов
            UHierarchy = new Hierarchy();
            TypeList   = UHierarchy.CreateTypeList();

            foreach (Type type in TypeList)
            {
                TypeCB.Items.Add(type.Name);
            }

            DPanel = DrawPanel.CreateGraphics();
            LineWeightLabel.Text = String.Format("Line weigth: {0}", LineWeigth);
        }
Пример #17
0
        /// <summary>
        /// Draws the graph on the DrawPanel's graphic surface.
        /// </summary>
        private void DrawGraph()
        {
            if (WindowState == FormWindowState.Minimized)
            {
                return;
            }

            if (Graph == null)
            {
                DrawPanel.Invalidate();
                return;
            }

            using (var graphics = DrawPanel.CreateGraphics())
                Graph.DrawAutomata(graphics, 0, 0, DrawPanel.Width, DrawPanel.Height);
        }
Пример #18
0
        private void ResetGame()
        {
            Graphics g = DrawPanel.CreateGraphics();

            g.Clear(DrawPanel.BackColor);
            MissedLabel.Text = "Missed :";
            counter          = 0;
            Lettertb.Text    = "";
            Wordtb.Text      = "";
            foreach (var item in labels)
            {
                item.Text = "";
            }
            labels.Clear();
            DrawHangPost();
        }
Пример #19
0
        /// <summary>
        /// Draws the modified automata based on the form fields' value.
        /// </summary>
        private void DrawPreviewAutomata()
        {
            if (WindowState == FormWindowState.Minimized)
            {
                return;
            }

            var graph = new AutomataGraph(Automata);

            if (SourceStateIdComboBox.SelectedIndex != -1 && TransitionComboBox.SelectedIndex != -1 && _comboBoxSelectionList.Count > TransitionComboBox.SelectedIndex)
            {
                var sourceDrawingState = graph.FindNode(SourceStateIdComboBox.SelectedItem as string) as State;

                foreach (var outEdge in sourceDrawingState.Edges)
                {
                    if (outEdge is Edge edge && edge.SourceNode == sourceDrawingState)
                    {
                        if (edge.LogicTransition == _comboBoxSelectionList[TransitionComboBox.SelectedIndex])
                        {
                            edge.Attr.Color      = MsaglColor.Red;
                            edge.Label.FontColor = MsaglColor.Red;
                        }
                        else
                        {
                            edge.Attr.Color      = MsaglColor.Orange;
                            edge.Label.FontColor = MsaglColor.Orange;
                        }
                    }
                }
            }

            var renderer = new GraphRenderer(graph);

            renderer.CalculateLayout();

            using (var graphics = DrawPanel.CreateGraphics())
            {
                graphics.SmoothingMode      = SmoothingMode.HighQuality;
                graphics.TextRenderingHint  = TextRenderingHint.AntiAliasGridFit;
                graphics.CompositingQuality = CompositingQuality.HighQuality;
                graphics.InterpolationMode  = InterpolationMode.HighQualityBicubic;

                renderer.Render(graphics, 0, 0, DrawPanel.Width, DrawPanel.Height);
            }
        }
Пример #20
0
        private void DrawBodyParts(BodyParts b)
        {
            Graphics   g  = DrawPanel.CreateGraphics();
            Pen        p  = new Pen(Color.Red, 3);
            SolidBrush br = new SolidBrush(Color.Black);

            switch (b)
            {
            case BodyParts.Head:
                g.DrawEllipse(p, 70, 60, 80, 80);
                break;

            case BodyParts.LeftEye:
                g.FillEllipse(br, 85, 75, 10, 10);
                break;

            case BodyParts.RightEye:
                g.FillEllipse(br, 120, 75, 10, 10);
                break;

            case BodyParts.Mouth:
                g.DrawArc(p, 85, 75, 50, 50, 45, 90);
                break;

            case BodyParts.Body:
                g.DrawLine(p, 110, 140, 110, 281);
                break;

            case BodyParts.LeftArm:
                g.DrawLine(p, 110, 180, 50, 150);
                break;

            case BodyParts.RightArm:
                g.DrawLine(p, 110, 180, 170, 150);
                break;

            case BodyParts.LeftLeg:
                g.DrawLine(p, 110, 280, 50, 350);
                break;

            case BodyParts.RightLeg:
                g.DrawLine(p, 110, 280, 170, 350);
                break;
            }
        }
Пример #21
0
        public FrmMain()
        {
            InitializeComponent();
            CanvasSize  = new Size(500, 500);
            Size        = new Size(CanvasSize.Width + 16, CanvasSize.Height + 74);
            MinimumSize = Size;
            MaximumSize = Size;

            DrawPanel = new DrawPanel()
            {
                Size = CanvasSize
            };
            DrawPanel.Paint     += new PaintEventHandler(OnCanvasPaint);
            DrawPanel.MouseDown += new MouseEventHandler(OnMouseDown);
            DrawPanel.MouseUp   += new MouseEventHandler(OnMouseUp);
            DrawPanel.MouseMove += new MouseEventHandler(OnMouseMove);
            Controls.Add(DrawPanel);
            canvas = DrawPanel.CreateGraphics();
        }
Пример #22
0
 /// <summary>
 /// 根据 DftData, 将频谱绘制到窗体
 /// </summary>
 /// <param name="s"></param>
 /// <param name="args"></param>
 private void RenderPanel(object s, EventArgs args)
 {
     if (bufferedGraphics == null || bufferedGraphics.Graphics == null)
     {
         bufferedGraphics = BufferedGraphicsManager.Current.Allocate(DrawPanel.CreateGraphics(), DrawPanel.ClientRectangle);
     }
     if (DftData == null || DftData.Length == 0 || frequencyPerIndex == 0)
     {
         return;
     }
     drawAction ??= MusicCircleVisualDraw;
     lock (DftDataLock)
     {
         bufferedGraphics.Graphics.Clear(DrawPanel.BackColor);
         //DarkerRender(DrawPanel.BackColor);
         //ColorRender(Color.Black, Color.Purple);
         MusicLineVisualDraw();
         MusicCircleVisualDraw();
         bufferedGraphics.Render();
     }
 }
Пример #23
0
        public void DrawPanel_Redraw()
        {
            using (Graphics g = DrawPanel.CreateGraphics())
            {
                using (Pen px = new Pen(ColorOx, SizeOxOy))
                {
                    px.EndCap = System.Drawing.Drawing2D.LineCap.DiamondAnchor;
                    g.DrawLine(px, new Point(0, DrawPanel.Height / 2), new Point(DrawPanel.Width, DrawPanel.Height / 2));

                    using (Pen py = new Pen(ColorOy, SizeOxOy))
                    {
                        py.EndCap = System.Drawing.Drawing2D.LineCap.DiamondAnchor;
                        g.DrawLine(py, new Point(DrawPanel.Width / 2, DrawPanel.Height), new Point(DrawPanel.Width / 2, 0));
                        if (PolyCreated)
                        {
                            this.DrawPolyPoints(LastPolyPts);
                        }
                    }
                }
            }
        }
Пример #24
0
        /// <summary>
        /// Draws the modified automata based on the form fields' value.
        /// </summary>
        private void DrawPreviewAutomata()
        {
            if (WindowState == FormWindowState.Minimized)
            {
                return;
            }

            var graph = new AutomataGraph(Automata);

            var selectedStateId = DeleteStateComboBox.SelectedItem as string;

            if (!String.IsNullOrWhiteSpace(selectedStateId) && Automata.GetState(selectedStateId) != null)
            {
                if (graph.FindNode(selectedStateId) is State state)
                {
                    state.Attr.Color      = MsaglColor.Red;
                    state.Label.FontColor = MsaglColor.Red;

                    foreach (var edge in state.Edges)
                    {
                        edge.Attr.Color      = MsaglColor.Red;
                        edge.Label.FontColor = MsaglColor.Red;
                    }
                }
            }

            var renderer = new GraphRenderer(graph);

            renderer.CalculateLayout();

            using (var graphics = DrawPanel.CreateGraphics())
            {
                graphics.SmoothingMode      = SmoothingMode.HighQuality;
                graphics.TextRenderingHint  = TextRenderingHint.AntiAliasGridFit;
                graphics.CompositingQuality = CompositingQuality.HighQuality;
                graphics.InterpolationMode  = InterpolationMode.HighQualityBicubic;

                renderer.Render(graphics, 0, 0, DrawPanel.Width, DrawPanel.Height);
            }
        }
Пример #25
0
        public void Draw3D(lib3Dmodel.Color[] C)
        {
            if (DrawPanel == null)
            {
                return;
            }
            Point P;
            Point P2;

            Graphics G = DrawPanel.CreateGraphics();

            G.Clear(System.Drawing.Color.FromArgb(255, 255, 255));

            for (int i = 0; i < ListVectors.Count; i++)
            {
                P = new Vector().ToScreen(ListVectors[i], new Point(DrawPanel.Width / 2, DrawPanel.Height / 2), Ang);

                // G.DrawLine(Pens.Black, P, P2);
                lib3Dmodel.Color Col = C[i];
                G.DrawRectangle(new Pen(System.Drawing.Color.FromArgb(Col.r, Col.g, Col.b)), P.X, P.Y, 1, 5);
            }
        }
Пример #26
0
        private void SysCoord(int xmax, int xmin, int ymax, int ymin, ref int h)
        {
            using (Graphics g = DrawPanel.CreateGraphics())
            {
                int r = DrawPanel.Height / 2;
                int tmaxx, tmaxy, tmax;
                if (Math.Abs(xmax) > Math.Abs(xmin))
                {
                    tmaxx = xmax;
                }
                else
                {
                    tmaxx = xmin;
                }
                if (Math.Abs(ymax) > Math.Abs(ymin))
                {
                    tmaxy = ymax;
                }
                else
                {
                    tmaxy = ymin;
                }
                if (Math.Abs(tmaxx) > Math.Abs(tmaxy))
                {
                    tmax = Math.Abs(tmaxx);
                }
                else
                {
                    tmax = Math.Abs(tmaxy);
                }
                h = (r / (tmax + 1));

                using (Pen p = new Pen(Color.White, SizeOxOy + 3))
                {
                    for (int i = 1; i < h; i++)
                    {
                        int ah1 = r + i * h;
                        int ah2 = r - i * h;
                        p.Color = ColorOx;
                        g.DrawLine(p, ah1, r + 5, ah1, r - 5);
                        g.DrawLine(p, ah2, r + 5, ah2, r - 5);
                        p.Color = ColorOy;
                        g.DrawLine(p, r + 5, ah1, r - 5, ah1);
                        g.DrawLine(p, r + 5, ah2, r - 5, ah2);
                    }
                }

                Point Start   = new Point(r, r);
                Point LabelOx = new Point(r * 2 - 25, r + 15);
                Point LabelOy = new Point(r + 15, 13);

                using (Brush Text = new SolidBrush(ColorText))
                {
                    using (Font Arial = new Font("Arial", SizeText + 2))
                    {
                        g.DrawString("0", Arial, Text, Start);
                        g.DrawString("Ox", Arial, Text, LabelOx);
                        g.DrawString("Oy", Arial, Text, LabelOy);
                    }
                }
            }
        }
Пример #27
0
        private void DrawTagNode(Dictionary <string, CardImg> tpks)
        {
            if (!Parameter.isSupportMulArea)
            {//不是多区域时,只有一张地图
                if (null == CurBitMap)
                {
                    return;
                }
            }
            Graphics g = null;

            try
            {
                if (!Parameter.isSupportMulArea)
                {
                    g = Graphics.FromImage(CurBitMap);
                }
            }
            catch (System.InvalidOperationException)
            {
                return;
            }
            float wscale = 0.0f, hscale = 0.0f;

            if (!Parameter.isSupportMulArea)
            {
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            }
            Brush  tagbrush = Brushes.Green;
            TagPen linetagpen = null; Pen linepen;

            System.Drawing.PointF[] points = null;
            double mapx = 0.0d, mapy = 0.0d, panelx = 0.0d, panely = 0.0d;
            string strtagid = "", strgroupid = "";

            foreach (CardImg tpk in tpks.Values)
            {
                strtagid = tpk.ID[0].ToString("X2") + tpk.ID[1].ToString("X2");
                if (tpk.Name == null || "".Equals(tpk.Name))
                {
                    tpk.Name = Ini.GetValue(Ini.CardPath, strtagid, Ini.Name);
                }
                if (!"".Equals(StrTagInfor) && !StrTagInfor.Equals(tpk.Name) && !StrTagInfor.Equals(tpk.ID[0].ToString("X2") + tpk.ID[1].ToString("X2")))
                {
                    continue;
                }
                if (Parameter.isSupportMulArea)
                {//支持多区域
                    strgroupid = tpk.GroupID[0].ToString("X2") + tpk.GroupID[1].ToString("X2");
                    Group group = null;
                    if (!frm.Groups.TryGetValue(strgroupid, out group))
                    {
                        continue;
                    }
                    DxfMapParam.ClearDxf();
                    CurBitMap = DxfMapParam.GetDxfMap(group.grouppath, Dxf.scale, DrawPanel.Width / 2, DrawPanel.Height / 2, DrawPanel.Width, DrawPanel.Height);
                    if (null == CurBitMap)
                    {
                        continue;
                    }
                    DrawPanel.CreateGraphics().DrawImageUnscaled(CurBitMap, 0, 0);
                    g         = Graphics.FromImage(CurBitMap);
                    wscale    = (float)DrawPanel.Width / group.actualwidth;
                    hscale    = (float)DrawPanel.Height / group.actualheight;
                    mrscale   = wscale > hscale ? hscale : wscale;
                    mapwid    = group.actualwidth * mrscale;
                    mapheight = group.actualheight * mrscale;
                }
                // 计算Tag在地图上的坐标
                mapx = mrscale * tpk.CardPoint.x;
                mapy = mrscale * tpk.CardPoint.y;
                // Tag在面板中的坐标
                panelx = (DrawPanel.Width - mapwid) / 2 + mapx;
                panely = (DrawPanel.Height - mapheight) / 2 + mapy;
                if (tpk.LocaType == TPPID.TagCommonLocal)
                {
                    tagbrush = Brushes.Green;
                }
                if (tpk.isOverNoMove)
                {
                    tagbrush = Brushes.Black;
                }
                if (tpk.isLowBattery)
                {
                    tagbrush = Brushes.Indigo;
                }
                if (tpk.LocaType == TPPID.TagWarmLocal)
                {
                    tagbrush = Brushes.Red;
                }
                if (TraceMode == 0)
                {
                    if (panelx <= 0 || panely <= 0)
                    {
                        continue;
                    }
                    g.FillEllipse(tagbrush, (float)(panelx - 4), (float)panely - 4, 8, 8);
                    if (null == tpk.Name || "".Equals(tpk.Name))
                    {
                        g.DrawString(tpk.ID[0].ToString("X2") + tpk.ID[1].ToString("X2"), new Font("宋体", 12), Brushes.Red, (float)(panelx + 4), (float)(panely + 6));
                    }
                    else
                    {
                        g.DrawString(tpk.Name + "(" + tpk.ID[0].ToString("X2") + tpk.ID[1].ToString("X2") + ")", new Font("宋体", 12), Brushes.Red, (float)(panelx + 4), (float)(panely + 6));
                    }
                }
                else
                {
                    linetagpen = GetTagPen(strtagid);
                    if (null == linetagpen)
                    {
                        if (AllTagPens.Count >= 6)
                        {
                            continue;
                        }
                        linetagpen = new TagPen();
                        System.Buffer.BlockCopy(tpk.ID, 0, linetagpen.ID, 0, 2);
                        linepen           = Get6Color();
                        linetagpen.tagpen = linepen;
                        linetagpen.Name   = tpk.Name;
                        AllTagPens.Add(linetagpen);
                        if (panelx >= 0 && panely >= 0)
                        {
                            linetagpen.oldx = panelx;
                            linetagpen.oldy = panely;
                        }
                    }
                    else
                    {
                        if (linetagpen.oldx <= 0 || linetagpen.oldy <= 0)
                        {
                            linetagpen.oldx = panelx;
                            linetagpen.oldy = panely;
                            return;
                        }
                        if (panelx > 0 && panely > 0)
                        {
                            if (null == points)
                            {
                                points = new PointF[2];
                            }
                            points[0] = new System.Drawing.PointF((float)linetagpen.oldx, (float)linetagpen.oldy);
                            points[1] = new System.Drawing.PointF((float)panelx, (float)panely);
                            try
                            {
                                g.DrawCurve(linetagpen.tagpen, points);
                            }
                            catch (System.OutOfMemoryException ex)
                            {
                                FreeMemory();
                                Console.WriteLine("内存不足!" + ex.ToString());
                            }
                        }
                        linetagpen.oldx = panelx; linetagpen.oldy = panely;
                    }
                }
                if (Parameter.isSupportMulArea)
                {
                    if (null == CurBitMap)
                    {
                        return;
                    }
                    DrawPanel_Paint(null, null);
                }
            }
            if (!Parameter.isSupportMulArea)
            {
                if (null == CurBitMap)
                {
                    return;
                }
                DrawPanel_Paint(null, null);
            }
            if (TraceMode == 1)
            {
                if (null == AllTagPens)
                {
                    return;
                }
                if (AllTagPens.Count <= 0)
                {
                    return;
                }
                int logox1 = 15, logoy1 = 0, logox2 = 45, logoy2 = 0;
                for (int i = 0; i < AllTagPens.Count; i++)
                {
                    if (null == AllTagPens[i])
                    {
                        continue;
                    }
                    if (AllTagPens[i].isLogo)
                    {
                        continue;
                    }
                    logoy1 = logoy2 = (i + 1) * 25;
                    if (null == AllTagPens[i].tagpen)
                    {
                        continue;
                    }
                    g.DrawLine(AllTagPens[i].tagpen, new System.Drawing.Point(logox1, logoy1), new System.Drawing.Point(logox2, logoy2));
                    if (null == AllTagPens[i].Name || "".Equals(AllTagPens[i].Name))
                    {
                        g.DrawString(AllTagPens[i].ID[0].ToString("X2") + AllTagPens[i].ID[1].ToString("X2"), new Font("宋体", 12), AllTagPens[i].tagpen.Brush, logox2 + 5, logoy2 - 8);
                    }
                    else
                    {
                        g.DrawString(AllTagPens[i].Name + "(" + AllTagPens[i].ID[0].ToString("X2") + AllTagPens[i].ID[1].ToString("X2") + ")", new Font("宋体", 12), AllTagPens[i].tagpen.Brush, logox2 + 5, logoy2 - 8);
                    }
                    AllTagPens[i].isLogo = true;
                }
            }
            if (null != g)
            {
                g.Dispose();
            }
        }
Пример #28
0
 private void radioButtonLine_CheckedChanged(object sender, EventArgs e)
 {
     primitive = new Line(DrawPanel.CreateGraphics());
 }
Пример #29
0
        private void ButtonValidate_Click(object sender, EventArgs e)
        {
            DrawPanel.Refresh();

            double ValueA = 0;
            double ValueB = 0;
            double ValueC = 0;
            double FirstX;
            double FirstY;

            int   origo_x = DrawPanel.Width / 2;
            int   origo_y = DrawPanel.Height / 2;
            Point origo   = new Point(origo_x, origo_y);

            Bitmap pen = new Bitmap(1, 1);

            pen.SetPixel(0, 0, Color.Blue);
            System.Drawing.Graphics g = DrawPanel.CreateGraphics();

            if (TextBoxValueA.Text == "" || TextBoxValueB.Text == "" || TextBoxValueC.Text == "")
            {
                MessageBox.Show("Veuillez remplir toute les cellules (en cas de valeur nulle entrer la valeur 0 et ne laisser pas la cellule vide)");
            }
            else
            {
                //ValueA = Convert.ToDouble(TextBoxValueA.Text) * (-1);
                //ValueB = Convert.ToDouble(TextBoxValueB.Text) * (-1);
                //ValueC = Convert.ToDouble(TextBoxValueC.Text) * (-1);
                ValueA = Convert.ToDouble(TextBoxValueA.Text);
                ValueB = Convert.ToDouble(TextBoxValueB.Text);
                ValueC = Convert.ToDouble(TextBoxValueC.Text);

                if (ValueA >= -10 && ValueA <= 10)
                {
                    if (ValueB >= -10 && ValueB <= 10)
                    {
                        if (ValueC >= -10 && ValueC <= 10)
                        {
                        }
                        else
                        {
                            MessageBox.Show("Veuiller entrer une valeur comprise entre -10 et 10");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Veuiller entrer une valeur comprise entre -10 et 10");
                    }
                }
                else
                {
                    MessageBox.Show("Veuiller entrer une valeur comprise entre -10 et 10");
                }

                //if ((Math.Pow(ValueB, 2) - (4 * ValueA * ValueC)) / (2 * ValueA) < 0) // Check if the discriminant is positiv
                //{
                //    FirstX = (-ValueB + Math.Sqrt(Math.Pow(ValueB, 2) - (4 * ValueA * ValueC))) / (2 * ValueA);
                //    SecondX = (-ValueB - Math.Sqrt(Math.Pow(ValueB, 2) - (4 * ValueA * ValueC))) / (2 * ValueA);
                //}
                //else if ((Math.Pow(ValueB, 2) - (4 * ValueA * ValueC)) / (2 * ValueA) == 0) // check if the discriminant is neutral
                //{
                //    FirstX = SecondX = -(ValueB / (2 * ValueA));
                //}
                //else
                //{

                //}

                //Début tableau
                Double[,] storePoint = new Double[201, 2];

                double minY = 0;
                double maxY = 0;

                //store
                for (double j = 0, i = -10; i <= 10 && j < 201; i += 0.1, j++)
                {
                    FirstX = i;
                    FirstY = (ValueA * (FirstX * FirstX)) + ((ValueB * FirstX) + ValueC);
                    storePoint[(int)j, 0] = FirstX;
                    storePoint[(int)j, 1] = FirstY;

                    //g.DrawImageUnscaled(pen, origo_x + (int)FirstX, origo_y - (int)FirstY);
                    //g.DrawImageUnscaled(pen, origo_x - (int)FirstX, origo_y - (int)FirstY);

                    if (maxY < storePoint[(int)j, 1] && storePoint[(int)j, 1] > 0)
                    {
                        maxY = storePoint[(int)j, 1];
                    }
                    if (minY > storePoint[(int)j, 1] && storePoint[(int)j, 1] < 0)
                    {
                        minY = storePoint[(int)j, 1];
                    }
                }


                if (Math.Abs(minY) > Math.Abs(maxY))
                {
                    maxY = minY;
                }

                double MaxYValue = maxY;
                MaxYValue = Math.Round(maxY);

                if (MaxYValue < 0)
                {
                    lblmaxY.Text = Convert.ToString(MaxYValue * (-1));
                    lblminY.Text = Convert.ToString(MaxYValue);
                }
                else if (MaxYValue > 0)
                {
                    lblmaxY.Text = Convert.ToString(MaxYValue);
                    lblminY.Text = "- " + Convert.ToString(MaxYValue);
                }
                maxY = Math.Abs(origo_y / maxY);



                //Draw
                for (int i = 0; i <= 200; i++)
                {
                    Point newpoint = new Point((int)((storePoint[i, 0] + 10) * (origo.X / 10)),
                                               (int)(origo_y - (maxY * storePoint[i, 1])));

                    //g.DrawImageUnscaled(pen, origo_x + (int)FirstX, origo_y - (int)FirstY);
                    //g.DrawImageUnscaled(pen, origo_x - (int)FirstX, origo_y - (int)FirstY);
                    //g.DrawImageUnscaled(pen, origo);
                    g.DrawImageUnscaled(pen, newpoint);
                }

                SaveDrawing();
            }
        }
Пример #30
0
 private void MainForm_Load(object sender, EventArgs e)
 {
     graph      = DrawPanel.CreateGraphics();
     graphState = PanelState.CreateGraphics();
 }