Greetings Everyone,
I need help to plot two graphics (of a different style (thumbnail and rectangular dot) in parallel using same data on an image. This GUI program executes in the following way:
- Reads text file contains the data points which have to be plotted.
- The program uses click button and the check box.
- After clicking up the button the program execution started with the plotting of the First graphic, however when the check box is checked the second graphic plotting started and when the check box unchecked the second graphic plotting stopped. Both of the graphics style using the same text file.
- The second graphic actually plots the trajectory of the first graphic. As when the user wants to observe the trajectory so clicks the check box in parallel with the First graphic.
-
I used the threading technique to read a text file and activates this thread under click button.
I need help what to do in this case, should I create the separate thread for check box for this parallel plotting
here I am sharing a block of my code, which I tried to implement but it plots the same graphic (i.e. First graphic) when the check box is operated and this scenario does not meet the program requirement. It plots the rectangular dot but as a single point, It should be plotted continuously till the check box is checked.
please help!!public partial class Form1 : Form
{
double w;
double z;
Thread T;
int flag;
delegate void refresh();
private System.Drawing.Graphics g;public Form1() { InitializeComponent(); } void refresh_PicBox() { if (pictureBox1.InvokeRequired) { refresh r = new refresh(refresh_PicBox); pictureBox1.Invoke(r); } else { pictureBox1.Refresh(); } } public void thread() { StreamReader file = new StreamReader(@"C:\Text.txt"); string line; int sc = 100; while ((line = file.ReadLine()) != null) { char[] del = new char[] { '\t' }; string[] part = line.Split(del, StringSplitOptions.RemoveEmptyEntries); w = Convert.ToDouble(part[0]) * sc; z = Convert.ToDouble(part[1]) * sc; g = pictureBox2.CreateGraphics(); if (flag == 0) { g.DrawImage(new Bitmap(@"C:\interface.png"), Convert.ToInt32(w), Convert.ToInt32(z), 20, 20); Thread.Sleep(50); refresh_PicBox();// invoke for refreshing picture box } if (flag == 1) { g.FillRectangle(Brushes.Blue, Convert.ToInt32(w), Convert.ToInt32(z), 9, 9); Thread.Sleep(50); } } } private void Form1_Load(object sender, EventArgs e) { pictureBox2.Image = new Bitmap(@"C:\Image.jpg"); } private void button2_Click(object sender, EventArgs e) { T = new Thread(thread); T.Start(); flag = 0; } private void checkBox2_CheckedChanged(object sender, EventArgs e) { if (checkBox2.Checked) { flag = 1; } else { flag = 0; } } }