Hi,
this is jagadeesh, iam visual studio 10 IDE and c# language for one grafical application .
for that application i used tabpages, one of that tab pages i have to draw graph in that page.it works also but while i selected another page the control goes to that page, after return to graph page the graph is vanished.but i didn't want that .any body can help abiut this problem.
here iam sending my sample code which is run in timer block
this graph raises between voltage and time
Code:
private void timer1_Tick_1(object sender, EventArgs e)
{
Graphics g = this.tabLoadPage.CreateGraphics();
//System.Drawing.Drawing2D.GraphicsState graph = g.Save();
//g.Restore(graph);
if (flg == true)
{
y1 = y2;
x2 = x2 + 5; // for increse time leve
flg = false;
}
else if (flg == false)
{
x1 = x2; // here i iam taking reference point of time level
y2 = Convert.ToInt16(398 - ((dta[load_val] / 1000) * 32.25)); ; // for increse voltage level
flg = true;
}
g.DrawLine(p, x1, y1, x2, y2);
}
this code was working in tabpage1(tabloadpage).if i press next tab page ,the controll goes to that age at that time graph is vanished .this is my problem please help me
thank you,
Last edited by Cimperiali; February 27th, 2012 at 08:08 AM.
Reason: added [code][/code] tags
You need to draw all of the lines every time in your Paint handler.
I just wrote this code, it may help you make some progress.
Code:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
List<Point> _points = new List<Point>();
Random _random = new Random();
public Form1()
{
InitializeComponent();
// at least two points are required...
_points.Add(new Point(0, 0));
_points.Add(new Point(this.Width, this.Height));
timer1.Start();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.DrawLines(Pens.Blue, _points.ToArray());
}
private void timer1_Tick(object sender, EventArgs e)
{
_points.Add(new Point(_random.Next(this.Width), _random.Next(this.Height)));
this.Invalidate();
}
}
}
Rob
-
Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......
Bookmarks