예제 #1
0
        private void Draw()
        {
            //hàm vẽ giá trị
            try
            {
                Graphics graph = PictureBox_DoThi.CreateGraphics();
                Point    toaDo = new Point();
                Point    ptAnt = new Point(0, 100);

                graph.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

                for (int ContItems = 0; ContItems <= Display_X_Y.Items.Count - 1; ContItems++)
                {
                    string str = Display_X_Y.Items[ContItems].ToString();
                    for (int ContChar = 0; ContChar < str.Length; ContChar++)
                    {
                        if (Display_X_Y.Items[ContItems].ToString().Substring(ContChar, 1) == " ")
                        {
                            toaDo.X  = Convert.ToInt32(str.Remove(ContChar, str.Length - ContChar));
                            toaDo.Y  = 100 - Convert.ToInt32(str.Remove(0, ContChar));
                            ContChar = str.Length;
                        }
                    }
                    graph.DrawLine(new Pen(Color.Blue, 2), ptAnt.X + 310, ptAnt.Y + 160, toaDo.X + 310, toaDo.Y + 160); //vẽ đường nối

                    graph.FillEllipse(new SolidBrush(Color.Red), toaDo.X + 310, toaDo.Y + 153, 6, 6);                   //vẽ chấm đỏ

                    graph.DrawLine(new Pen(Color.Black, 1), 0, 260, 620, 260);                                          //vẽ trục X

                    graph.DrawLine(new Pen(Color.Black, 1), 310, 1, 310, 520);                                          //vẽ trục Y



                    graph.DrawString("O",
                                     new Font("Palatino Linotype", 10, FontStyle.Bold),
                                     new SolidBrush(Color.Black), 310, 260);//ghi tâm O

                    graph.DrawString("Y",
                                     new Font("Palatino Linotype", 10, FontStyle.Bold),
                                     new SolidBrush(Color.Black), 310, 1); // ghi trục y

                    graph.DrawString("X",
                                     new Font("Palatino Linotype", 10, FontStyle.Bold),
                                     new SolidBrush(Color.Black), 600, 260); // ghi trục x



                    ptAnt = toaDo;
                }
            }
            catch (Exception ex2)
            {
                MessageBox.Show(ex2.Message, "LỖI VẼ HÌNH");
            }
        }
예제 #2
0
 private void button_Clear_Click(object sender, EventArgs e)
 {
     try
     {
         File.WriteAllText(@"savedata.txt", String.Empty);
     }
     catch (Exception ex4)
     {
         {
             MessageBox.Show(ex4.Message, "LỖI XÓA FILE");
         }
     }
     // xóa đồ thị và list box
     PictureBox_DoThi.Refresh();
     Display_X_Y.Refresh();
     Display_X_Y.ResetText();
     Display_X_Y.Items.Clear();
 }