我用graphics在groupbox中画了一个单坐标轴(X轴),坐标轴表示的是从0-100%,我想用一个垂直走向的线段指示当前示数(比如说当前值为Value),我现在的做法是每修改一次Value的值,都要调用graphics.clear()清除上一次画的图像,然后重新画。这样一来在清除线段的同时就连坐标轴一起清空了,所以没更改一次Value值我就得连坐标轴和线段都重画。效率很低有没有好的方法,望高手指点...
解决方案 »
- 大家帮看看下面代码哪错了
- WPF中DataGrid设置了IsReadOnly="false"仍然不可编辑
- 请教个sql问题?
- vs2008中的.sdf(数据库文件)是什么意思,怎么用?
- 形如这样的正则表达式怎么写*****Begin%VB.ddddddd%dddddddd、望高人能给指点指点
- DataGridView数据源为对象集的两个问题
- 一个难解的存储过程
- 请教,关于在asp.net模式下用c#调用sendarp来获得客户端的mac,为什么在有些windows 2003上sendarp操作失败呢
- application folder参数
- {各位高手来看看,急啊!!!} visual studio 2005制作安装包的问题
- C#多线程问题。。
- ActiveX ,ocx控件问题
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();
}
}
}
坐标上面的值是根据TEXTbox5中的具体值算出来的,请指点,在线等,谢谢
picturebox1.backgroundimage=c:\坐标轴.bmpdrawvalue()
picturebox1.invaldate()
....
g.drawlines(...
网站
我们的水平和国外还是差很远。
my blog
http://ufo-crackerx.blog.163.com/
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(); //这里可以传入要更新的区域,不过我觉得没有必要,反而破坏了算法的简洁性,如果不是刻意地追求效率
}
}
}
这样不是更好吗?
pictureBox1.Invalidate();把pictureBox1传给你的自定义控件。
{
get;set;
}