private void HuiZhiTu( string strPaiXu){//初始数据int[] nums = { 150, 89, 200, 60, 70, 90 };if (strPaiXu == "升序"){//冒泡排序for (int i = 0; i < nums.Length; i++){for (int j = 0; j < nums.Length-1; j++){if (nums[i] > nums[j]){int temp = nums[i];nums[i] = nums[j];nums[j] = temp;}}}}else if (strPaiXu == "降序"){//冒泡排序for (int i = 0; i < nums.Length; i++){for (int j = 0; j < nums.Length-1; j++){if (nums[i] < nums[j]){int temp = nums[i];nums[i] = nums[j];nums[j] = temp;}}}}else{//正常的顺序 }label1.Text = strPaiXu;//创建画布int panHeight = this.panel1.Height;int panWight = this.panel1.Width;Bitmap bitM = new Bitmap(panWight, panHeight);Graphics g = Graphics.FromImage(bitM);g.Clear(Color.White);//绘制横向线条for (int i = 0; i < 5; i++){g.DrawString(i * 50 + "", new Font("宋体", 10, FontStyle.Regular), new SolidBrush(Color.Black), 20, 50 * (5 - i) - 7);g.DrawLine(new Pen(Color.Red), 50, 50 * i + 50, 500, 50 * i + 50);}//绘制纵向线条g.DrawLine(new Pen(Color.Red), 50, 0, 50, 250);//填充数据for (int i = 0; i < nums.Length; i++){g.FillRectangle(new SolidBrush(Color.Red), 50 * i + 80, 250 - nums[i], 40, nums[i]);}this.panel1.BackgroundImage = bitM;}private void btn_HuiZhi_Click(object sender, EventArgs e){HuiZhiTu("正常顺序");}private void btn_ShengXu_Click(object sender, EventArgs e){HuiZhiTu("升序");}private void btn_JiangXu_Click(object sender, EventArgs e){HuiZhiTu("降序");}