コード例 #1
0
        //直接在显示时绘图
        private void Form2_Shown(object sender, EventArgs e)
        {
            //获取当前图形
            Graphics g = this.CreateGraphics();

            //创建新原点
            PointF origin = new PointF(40, this.Height - 80);

            //绘制坐标系的初始线
            g.DrawLine(new Pen(Brushes.Black, 2), origin, new PointF(this.Width, this.Height - 80));
            g.DrawLine(new Pen(Brushes.Black, 2), origin, new PointF(40, 0));
            PointF p1;
            PointF p2;

            //绘制刻度
            for (int i = 1; i * 20 + 40 < this.Width; i++)
            {
                p1 = new PointF(40 + i * 20, this.Height - 80);
                p2 = new PointF(40 + i * 20, this.Height - 85);
                g.DrawLine(new Pen(Brushes.Black, 1), p1, p2);
                if (i % 5 == 0)
                {
                    p2 = new PointF(30 + i * 20, this.Height - 75);
                    g.DrawString((i * 20).ToString(), new Font("黑体", 8, FontStyle.Bold), new SolidBrush(Color.Black), p2);
                }
            }
            //绘制刻度下方的字符串
            for (int i = 1; i * 20 + 40 < this.Height; i++)
            {
                g.DrawLine(new Pen(Brushes.Black, 1), new PointF(40, this.Height - 80 - 20 * i), new PointF(45, this.Height - 80 - i * 20));
                if (i % 5 == 0)
                {
                    p2 = new PointF(15, this.Height - 85 - 20 * i);
                    g.DrawString((i * 20).ToString(), new Font("黑体", 8, FontStyle.Bold), new SolidBrush(Color.Black), p2);
                }
            }
            //绘制字符串x和y和原点0
            p2 = new PointF(30, this.Height - 75);
            g.DrawString("0", new Font("黑体", 8, FontStyle.Bold), new SolidBrush(Color.Black), p2);
            p2 = new PointF(this.Width - 30, this.Height - 77);
            g.DrawString("x", new Font("黑体", 8, FontStyle.Bold), new SolidBrush(Color.Black), p2);
            p2 = new PointF(30, 5);
            g.DrawString("y", new Font("黑体", 8, FontStyle.Bold), new SolidBrush(Color.Black), p2);

            //获取数据集
            data_Set_Block data_Block = form1.get_Data_Block(index0);
            //获取数据组个数
            int item_Count = data_Block.get_Item_Count();

            for (int i = 0; i < item_Count; i++)
            {
                item_Set item = data_Block.get_Item(i);
                //绘制当前数据组
                for (int j = 0; j < 3; j++)
                {
                    draw_Point(item.get_Profit(j), item.get_Weight(j));
                }
            }
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: haixiujun/D-01-Bag
        //在文件数据全部读取到中间数据字符串后写入中间数据文件再进行切割
        private void cut_Data_Set()
        {
            //清空数据集和列表1
            data_Sets.Clear();
            listBox1.Items.Clear();

            //文件行数要去掉第一行和最后一行的开始结束符
            file_Lines_Count -= 2;

            //去掉第一行
            int first_Line_End_Index = temp_Data.IndexOf('\n');

            temp_Data = temp_Data.Remove(0, first_Line_End_Index + 1);

            //去掉最后一行
            int last_Line_Start_Index = temp_Data.LastIndexOf('\n');

            temp_Data = temp_Data.Substring(0, last_Line_Start_Index);

            //写入中间数据文件
            string       temp = "";
            StreamWriter sw   = new StreamWriter("test.txt");

            sw.Write(temp_Data);
            sw.Close();

            //检测是否是6的倍数,每个数据集在文件中应该为6行
            if (file_Lines_Count % 6 != 0)
            {
                MessageBox.Show("File Error!");
                return;
            }

            //通过文件行数来计算数据集的数量
            group_Counts = file_Lines_Count / 6;

            StreamReader sr = new StreamReader("test.txt");

            for (int i = 0; i < group_Counts; i++)
            {
                data_Set_Block temp_Set;
                //奇数行为提示信息,不需要进行处理,仅对偶数行进行处理
                temp = sr.ReadLine();
                temp = sr.ReadLine();
                //提取d和c的字符串
                string[] blocks = temp.Split(",");
                string   d_Str  = blocks[0].Split("*")[1];
                string   c_Str  = blocks[1].Split(" ").Last();

                //去掉结尾的字符
                c_Str = c_Str.Substring(0, c_Str.Length - 1);

                //将d和c的字符串转为整型
                int temp_d = Convert.ToInt32(d_Str);
                int temp_c = Convert.ToInt32(c_Str);

                //初始化当前数据集
                temp_Set = new data_Set_Block(temp_d, temp_c);

                //读取profit行的字符串
                temp = sr.ReadLine();
                temp = sr.ReadLine();
                //切割profit行字符串
                temp = temp.Substring(0, temp.Length - 1);
                string[] profit_Array_Str = temp.Split(",");

                //读取weight行的字符串
                temp = sr.ReadLine();
                temp = sr.ReadLine();
                //切割weight行字符串
                temp = temp.Substring(0, temp.Length - 1);
                string[] weight_Array_Str = temp.Split(",");

                //初始化profit和weight数组
                int[] profit_Array = new int[profit_Array_Str.Length];
                int[] weight_Array = new int[weight_Array_Str.Length];
                for (int j = 0; j < profit_Array_Str.Length; j++)
                {
                    //对应转换
                    profit_Array[j] = Convert.ToInt32(profit_Array_Str[j]);
                    weight_Array[j] = Convert.ToInt32(weight_Array_Str[j]);
                }

                //初始化数据集的profit和weight数组
                temp_Set.init_Item_Sets(profit_Array, weight_Array);
                //加入数据集列表中
                data_Sets.Add(temp_Set);
                //在listbox中添加当前数据集选项
                listBox1.Items.Add(openFileDialog1.SafeFileName + "-" + i.ToString());
            }
            sr.Close();
            //删除中间文件
            File.Delete("test.txt");
        }
コード例 #3
0
 public out_Put_Data(data_Set_Block data)
 {
     data_Set_Block = data;
 }
コード例 #4
0
ファイル: third_Sort.cs プロジェクト: haixiujun/D-01-Bag
 public third_Sort(data_Set_Block data)
 {
     data_Set = data;
     InitializeComponent();
 }