B
Btb4198
Guest
ok I make a process bar and that works. now, I have it in a pop up window and I want it to update while some word is being done in another thread(not the main thread). Anyhow, I am trying to update the process using information from that other thread but it is not updating. I am using a for loop in the other thread and I am using the I so find what percent I have left to go. here in my code:
void callPopUp()
{
new Thread(() => new PopUp().ShowDialog()).Start();
}
//___ other thread
bool running(int Baseline)
{
HomeMO();
tcClient.WriteAny(statenumber, Int16.Parse("11"));
while ( state != 11)
{
Thread.Sleep(500);
tcClient.WriteAny(statenumber, Int16.Parse("11"));
}
StepInfo step= get_StepInfo();
int point = step.Start_Step;
callPopUp();
stepPass = step.degress;
startStep = step.Start_Step;
stopStep = step.End_Step;
for ( int i =0; i < step.runcount; i++)
{
try
{
callPopUp(i, step);
...
now that is in my main form. here is the code in my popup form:
private void t_Tick(object sender, EventArgs e)
{
// graphics
g = Graphics.FromImage(bmp);
// clear grapthic
g.Clear(Color.LightBlue);
//draw progressbar
g.FillRectangle(Brushes.CornflowerBlue, new Rectangle(0, 0,(int)(percent * pbUNit), (int)pbHEIGHT));
// draw % complete
g.DrawString(percent + " %", new Font("Arial", (pbHEIGHT / 2F)), Brushes.Black, new PointF((pbWIDTH/2F)-20, (pbHEIGHT/2F)-20));
//load bitmap in picturebox
pictureBox1.Image = bmp;
if(percent > 100)
{
// dispose
g.Dispose();
t.Stop();
}
}
}
that is the timer that draws the process bar. but somehow the percent is not updating. here is the whole form:
public partial class PopUp : Form
{
Timer t = new Timer();
double pbUNit;
float pbWIDTH, pbHEIGHT, pbComplete;
Bitmap bmp;
Graphics g;
private int percent =0;
public string Title;
public int Percents
{
get { return percent; }
set { percent = value; }
}
public PopUp()
{
InitializeComponent();
this.Text = Title;
}
private void PopUp_Load(object sender, EventArgs e)
{
this.Text = Title;
pbWIDTH = pictureBox1.Width;
pbHEIGHT = pictureBox1.Height;
pbUNit = pbWIDTH / 100.0;
// pbComplete - this is equal to work completed in % [min = 0 max= 100]
pbComplete = 0;
bmp = new Bitmap((int)pbWIDTH, (int)pbHEIGHT);
//timer
t.Interval = 50;
t.Tick += new EventHandler(this.t_Tick);
t.Start();}
again this works good if I just put in a counter in the popup form. but it does not work when I send data to the popup window. it just stays at 0;
lso, I did try .show but then the pop up form does come up, but I cannot see my process bar at all.
Continue reading...
void callPopUp()
{
new Thread(() => new PopUp().ShowDialog()).Start();
}
//___ other thread
bool running(int Baseline)
{
HomeMO();
tcClient.WriteAny(statenumber, Int16.Parse("11"));
while ( state != 11)
{
Thread.Sleep(500);
tcClient.WriteAny(statenumber, Int16.Parse("11"));
}
StepInfo step= get_StepInfo();
int point = step.Start_Step;
callPopUp();
stepPass = step.degress;
startStep = step.Start_Step;
stopStep = step.End_Step;
for ( int i =0; i < step.runcount; i++)
{
try
{
callPopUp(i, step);
...
now that is in my main form. here is the code in my popup form:
private void t_Tick(object sender, EventArgs e)
{
// graphics
g = Graphics.FromImage(bmp);
// clear grapthic
g.Clear(Color.LightBlue);
//draw progressbar
g.FillRectangle(Brushes.CornflowerBlue, new Rectangle(0, 0,(int)(percent * pbUNit), (int)pbHEIGHT));
// draw % complete
g.DrawString(percent + " %", new Font("Arial", (pbHEIGHT / 2F)), Brushes.Black, new PointF((pbWIDTH/2F)-20, (pbHEIGHT/2F)-20));
//load bitmap in picturebox
pictureBox1.Image = bmp;
if(percent > 100)
{
// dispose
g.Dispose();
t.Stop();
}
}
}
that is the timer that draws the process bar. but somehow the percent is not updating. here is the whole form:
public partial class PopUp : Form
{
Timer t = new Timer();
double pbUNit;
float pbWIDTH, pbHEIGHT, pbComplete;
Bitmap bmp;
Graphics g;
private int percent =0;
public string Title;
public int Percents
{
get { return percent; }
set { percent = value; }
}
public PopUp()
{
InitializeComponent();
this.Text = Title;
}
private void PopUp_Load(object sender, EventArgs e)
{
this.Text = Title;
pbWIDTH = pictureBox1.Width;
pbHEIGHT = pictureBox1.Height;
pbUNit = pbWIDTH / 100.0;
// pbComplete - this is equal to work completed in % [min = 0 max= 100]
pbComplete = 0;
bmp = new Bitmap((int)pbWIDTH, (int)pbHEIGHT);
//timer
t.Interval = 50;
t.Tick += new EventHandler(this.t_Tick);
t.Start();}
again this works good if I just put in a counter in the popup form. but it does not work when I send data to the popup window. it just stays at 0;
lso, I did try .show but then the pop up form does come up, but I cannot see my process bar at all.
Continue reading...