110,534
社区成员
发帖
与我相关
我的任务
分享
pictureBox1.Invalidate();
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace Paint
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int x1=10;
int max = 600;
public void GrahpicsUpdate(Graphics graphics)
{
Pen mypen = new Pen(Color.Black);
Pen mypen1 = new Pen(Color.Red);
System.Drawing.Font font = new System.Drawing.Font("Arial", 8, FontStyle.Regular);
graphics.DrawLine(mypen, 0, 192, 700, 192);
String[] n = { "0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%", "100%" };
int xstart = 10;
for (int i = 0; i < 11; i++)
{
graphics.DrawString(n[i].ToString(), font, Brushes.DarkGray, xstart - 7, 192);//.Red
int Xmin = xstart;
for (int j = 0; j < 9; j++)
{
Xmin += 6;
if (j == 4) graphics.DrawLine(mypen, Xmin, 184, Xmin, 192);
else graphics.DrawLine(mypen, Xmin, 188, Xmin, 192);
}
graphics.DrawLine(mypen, xstart, 182, xstart, 192);
xstart = xstart + 60;
}
graphics.DrawLine(mypen1, x1, 180, x1, 200);
}
private void groupBox2_Paint(object sender, PaintEventArgs e)
{
GrahpicsUpdate(e.Graphics);
}
private void textBox5_TextChanged(object sender, EventArgs e)
{
double d = Convert.ToDouble(textBoxPresentVal.Text);
x1 = (int)(d / 100 * max)+10;
groupBox1.Invalidate(); //这里可以传入要更新的区域,不过我觉得没有必要,反而破坏了算法的简洁性,如果不是刻意地追求效率
}
}
}
public static void GrahpicsUpdate()
{
System.Drawing.Font font = new System.Drawing.Font("Arial", 8, FontStyle.Regular);
graphics.DrawLine(mypen, 0, 192, 700, 192);
//String[] n = { "0", ((double)MaxValue / 6).ToString(), ((double)MaxValue / 3).ToString(), ((double)MaxValue / 2).ToString(), ((double)MaxValue * 2 / 3).ToString(), ((double)MaxValue * 5 / 6).ToString(), ((double)MaxValue).ToString() };
String[] n = { "0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%", "100%" };
int xstart = 10;
for (int i = 0; i < 11; i++)
{
graphics.DrawString(n[i].ToString(), font, Brushes.DarkGray , xstart - 7, 192);//.Red
int Xmin = xstart;
for (int j = 0; j < 9; j++)
{
Xmin += 6;
if (j == 4) graphics.DrawLine(mypen, Xmin, 184, Xmin, 192);
else graphics.DrawLine(mypen, Xmin, 188, Xmin, 192);
}
graphics.DrawLine(mypen, xstart, 182, xstart, 192);
xstart = xstart + 60;
Thread.Sleep(1);
}
//graphics.DrawRectangle(mypen, 8, 192, 600, 10);
graphics1.DrawLine(mypen1, x1, 180, x1, 200);
}
private void groupBox2_Paint(object sender, PaintEventArgs e)
{
System.Drawing.Font font = new System.Drawing.Font("Arial", 8, FontStyle.Regular);
graphics.DrawLine(mypen, 0, 192, 700, 192);
String[] n = { "0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%", "100%" };
int xstart = 10;
for (int i = 0; i < 11; i++)
{
graphics.DrawString(n[i], font, Brushes.DarkGray, xstart - 7, 192);//.Red
int Xmin = xstart;
for (int j = 0; j < 9; j++)
{
Xmin += 6;
if (j == 4) graphics.DrawLine(mypen, Xmin, 184, Xmin, 192);
else graphics.DrawLine(mypen, Xmin, 188, Xmin, 192);
}
graphics.DrawLine(mypen, xstart, 182, xstart, 192);
xstart = xstart + 60;
Thread.Sleep(1);
}
//graphics.DrawRectangle(mypen, 8, 192, 600, 10);
graphics1.DrawLine(mypen1, x1, 180, x1, 200);
}
private void textBox5_TextChanged(object sender, EventArgs e)
{
if (textBoxPresentVal.Text.Trim() != "")
{
double newdate = Convert.ToDouble(textBoxPresentVal.Text.Trim());
textBoxDiffer .Text = (1000*(newdate - Form_Main .CurrentStandOut ) / Form_Main.MaxValue).ToString();
int x = Convert.ToInt32(10 + newdate * 600 / Form_Main.MaxValue);
//if (graphics1 .TranslateClip ())
//graphics1.Clear(Color.White );.Transparent
if (Form_Main.XCount1 == 0)
{
Form_Main.graphics1.Clear(Color.WhiteSmoke);
Form_Main.graphics1.DrawLine(Form_Main.mypen1, x, 182, x, 202);
Form_Main.x1 = x;
Form_Main.XCount1++;
Form_Main.GrahpicsUpdate();
}
else
{
Form_Main.graphics1.Clear(Color.WhiteSmoke);
//Form_Main.graphics1.DrawLine(Form_Main.mypen1, x, 182, x, 202);
Form_Main.graphics1.TranslateClip(x - Form_Main.x1, 0);// .TranslateTransform
Form_Main.x1 = x;
Form_Main.XCount1++;
Form_Main.GrahpicsUpdate();
}
}
}