private void temperatureToolStripMenuItem_click(object sender, EventArgs e) { TemperaturePanel.BringToFront(); menuStrip1.BringToFront(); TemperaturePanel.Enabled = true; BasicPanel.Enabled = false; SetDefault(tempBtnConvert); }
/// <summary> /// 画点和图 /// </summary> /// <param name="temperature"></param> private void Draw(double temperature) { temperatureText[num] = temperature; float y = (float)(temperature - 20) * 50; pointf[num] = new PointF(move1 += 25f, y); System.Diagnostics.Debug.WriteLine("PointF.Owid:" + pointf[num].X + ", Pointf.Ohei:" + pointf[num].Y); pointf[num].Y = TemperaturePanel.Height - move - pointf[num].Y; System.Diagnostics.Debug.WriteLine("PointF.wid:" + pointf[num].X + ", Pointf.hei:" + pointf[num].Y); drawline.DrawFillEllipse(graphics, pointf[num]); //drawline.DrawTextBox(graphics, Convert.ToString(temperature), pointf[num]); drawline.DrawTextBox(graphics, Convert.ToString(count++), pointf[num]); switch (num) { case 0: num++; break; case 20: bitmap = new Bitmap(TemperaturePanel.Width, TemperaturePanel.Height); graphics = Graphics.FromImage(bitmap); graphics.Clear(Color.White); for (int i = 0; i < num; i++) { pointf[i] = pointf[i + 1]; temperatureText[i] = temperatureText[i + 1]; } DrawOldLine(pointf, temperatureText); // num=num-1; break; default: if (alarmTemperature == 0) { drawline.Drawline(graphics, pointf[num - 1], pointf[num], lineColor); } // pointf[num].Y = TemperaturePanel.Height - move - (float)(alarmTemperature - 20) * 50; else { drawline.Drawline(graphics, pointf[num - 1], pointf[num], lineColor, (float)TemperaturePanel.Height - move - (float)(alarmTemperature - 20) * 50); } num++; break; } TemperaturePanel.Refresh(); }
/// <summary> /// 清空温度折线图 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void clearTeampaturebutton_Click(object sender, EventArgs e) { bitmap = new Bitmap(TemperaturePanel.Width, TemperaturePanel.Height); graphics = Graphics.FromImage(bitmap); graphics.Clear(Color.White); num = 0; move1 = move; count = 1; //一次性点的个数 TemperaturePanel.Refresh(); // logWriter.WriteLine(DateTime.Now.ToString() + ": " + LoginForm.userType + '\t' + LoginForm.userName + "\t 点击清除图片"); }
/// <summary> /// 折线实时更新,折线先后拖曳 /// </summary> /// <param name="temperature"></param> private void DrawOldLine(PointF[] oldPointf, double[] oldWenDu) { if (alarmTextBox.Text.Trim().Length > 0) { alarmTemperature = Convert.ToDouble(alarmTextBox.Text); float newX = TemperaturePanel.Width - move; float newY = (float)TemperaturePanel.Height - move - (float)(alarmTemperature - 20) * 50; //画温度警报线 PointF px1 = new PointF(move, newY); PointF px2 = new PointF(newX, newY); graphics.DrawLine(new Pen(Brushes.Red, 2), px1, px2); //drawline.Drawline(graphics, pointf[num - 1], pointf[num], lineColor, (float)TemperaturePanel.Height - move - (float)(alarmTemperature - 20) * 50); } float move2 = TemperaturePanel.Width - move; float x = move1; int count2 = count; PointF[] p = new PointF[20]; for (int i = num - 1; i >= 0; i--) { float y = (float)(oldWenDu[i] - 20) * 50; oldPointf[i] = new PointF(move2, y); oldPointf[i].Y = TemperaturePanel.Height - move - oldPointf[i].Y; drawline.DrawFillEllipse(graphics, oldPointf[i]); drawline.DrawTextBox(graphics, Convert.ToString(count2--), oldPointf[i]); move2 -= 25f; p[i] = oldPointf[i]; } for (int i = 1; i < 20; i++) { if (alarmTemperature == 0) { drawline.Drawline(graphics, p[i - 1], pointf[i], lineColor); } // pointf[num].Y = TemperaturePanel.Height - move - (float)(alarmTemperature - 20) * 50; else { drawline.Drawline(graphics, pointf[i - 1], pointf[i], lineColor, (float)TemperaturePanel.Height - move - (float)(alarmTemperature - 20) * 50); } } // graphics.DrawLines(lineColor, p); TemperaturePanel.Refresh(); }