status bar

G

Guest

i have a little bit of issue getting the status bar to work properly.
this is what happens now.

when the program loaded, the status is "READY..."
the code is inside the FORM LOAD.

i also added the same code in another CLICK METHOD.
everytime i click, the status got updated but the old "READY..." got moved up one line above.
so, if i click 10 times, i got a stack of 10 rows of status bar.

the question is.......
how do i destroy the old status bar and update the new info and leaving it at the same position?


thanks in advance,
Ada
 
A

Aravind C

Hi Ada,

Typically, the StatusBar.Text or the StatusBarPanel.Text property (if using
panels
in the status bar) should take care of updating the status bar text.
Can you post a snippet of code in your Click handler that
updates the status bar text ?.
That will help us track down the cause of the issue

Regards,
Aravind C
 
G

Guest

hi AC

below is the snippet
note, this is the exact same code in MSDN

// // Create a StatusBar control
// StatusBar statusBar1 = new StatusBar()
/
// StatusBarPanel panel1 = new StatusBarPanel()

// panel1.BorderStyle = StatusBarPanelBorderStyle.Sunken
// // Initialize the text of the panel
// panel1.Text = "Ready..."
// // Set the AutoSize property to use all remaining space on the StatusBar
// panel1.AutoSize = StatusBarPanelAutoSize.Spring
//
// // Display panels in the StatusBar control
// statusBar1.ShowPanels = true
//
// statusBar1.Panels.Add(panel1)
//
/
// // Add the StatusBar to the form
// this.Controls.Add(statusBar1)



----- Aravind C wrote: ----

Hi Ada

Typically, the StatusBar.Text or the StatusBarPanel.Text property (if usin
panel
in the status bar) should take care of updating the status bar text
Can you post a snippet of code in your Click handler tha
updates the status bar text ?
That will help us track down the cause of the issu

Regards
Aravind
 
A

Aravind C

Hi Ada,

From what I undestand, in your Click handler, you call the
snippet of code that you posted. Correct ?.

Actually, you must call the code that creates and adds the
status bar to the form's control collection only once -
prefeably in the designer generated InitializeComponent()
called in the Form's Constructor or in Form's Load event handler.
Otherwise we would end up creating and adding multiple instances of the
status bar to the windows form - which explains the behavior
you're seeing with the status bars being stacked one on top of another.

For updating the status bar's text, it may be enough to call,
panel1.Text = "....some text ...."; in your Click handler.

Regards,
Aravind C
 
G

Guest

hi AC

that's what i did previously before i posted the message on this board
i was thinking because the code, although it's the same, appear twice in different method, C# compiler would do all the clean up automatically

i tried your suggestion below
no go
code doesn't even compile
err msg
C:\Form1.cs(694): The type or namespace name 'panel1' could not be found (are you missing a using directive or an assembly reference?

i think what happened here is that although the object got instantiated on the LOAD FORM method but it got destroyed when it exited LOAD FORM
when i click on another method which contained the same code, it looks for the INSTANCE
in this case, of course, i think it's out of scope
this is the reason why i added all enchilada again
obvioulsy, something didn't go as plan

i was thinking may be there's a DISPOSE() method somewhere i can call before create the new instance in the new method
may be that can take care of the problem

anyhow, i'm all open for any advice. :-

--Ad




----- Aravind C wrote: ----

Hi Ada

From what I undestand, in your Click handler, you call th
snippet of code that you posted. Correct ?

Actually, you must call the code that creates and adds th
status bar to the form's control collection only once
prefeably in the designer generated InitializeComponent(
called in the Form's Constructor or in Form's Load event handler
Otherwise we would end up creating and adding multiple instances of th
status bar to the windows form - which explains the behavio
you're seeing with the status bars being stacked one on top of another

For updating the status bar's text, it may be enough to call
panel1.Text = "....some text ...."; in your Click handler

Regards
Aravind
 
A

Aravind C

Hi Ada,

Actually, you must make the statusbar and its panels as _instance fields_
of the Form so that the form can access them from any method.
The windows form designer should automatically do this for you once you
drag and drop a status bar from the toolbox into the form.

public class MyForm : System.Windows.Forms.Form
{
private System.Windows.Forms.StatusBar statusBar1;
private System.Windows.Forms.StatusBarPanel statusBarPanel1;

private void InitializeComponent()
{

this.statusBar1.Location = new System.Drawing.Point(0, 328);
this.statusBar1.Name = "statusBar1";
this.statusBar1.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[]
{
this.statusBarPanel1});
this.statusBar1.ShowPanels = true;
this.statusBar1.Size = new System.Drawing.Size(672, 22);
this.statusBar1.TabIndex = 2;
this.statusBar1.Text = "statusBar1";


this.statusBarPanel1.BorderStyle =
System.Windows.Forms.StatusBarPanelBorderStyle.Raised;
this.statusBarPanel1.Text = "Ready....";
this.statusBarPanel1.ToolTipText = "Test";

// ....

}

// Update the status panel's text
private void button1_Click(object sender, System.EventArgs e)
{
this.statusBarPanel1.Text = "Button clicked...";
}
}


Regards,
Aravind C



Ada said:
hi AC,

that's what i did previously before i posted the message on this board.
i was thinking because the code, although it's the same, appear twice in
different method, C# compiler would do all the clean up automatically.
i tried your suggestion below.
no go.
code doesn't even compile.
err msg:
C:\Form1.cs(694): The type or namespace name 'panel1' could not be found
(are you missing a using directive or an assembly reference?)
i think what happened here is that although the object got instantiated on
the LOAD FORM method but it got destroyed when it exited LOAD FORM.
when i click on another method which contained the same code, it looks for the INSTANCE.
in this case, of course, i think it's out of scope.
this is the reason why i added all enchilada again.
obvioulsy, something didn't go as plan.

i was thinking may be there's a DISPOSE() method somewhere i can call
before create the new instance in the new method.
 
G

Guest

hi AC

i think your suggestion might work
this is what i have in mind also

if i make it GLOBAL (as you suggested), then i don't have to recreate the object everytime

i will give this code a try after i woke up
it is about 4 a.m. my time zone now
betta catch some zzzzzzzzzzz

thanks for all the help
Ad




----- Aravind C wrote: ----

Hi Ada

Actually, you must make the statusbar and its panels as _instance fields
of the Form so that the form can access them from any method
The windows form designer should automatically do this for you once yo
drag and drop a status bar from the toolbox into the form

public class MyForm : System.Windows.Forms.For

private System.Windows.Forms.StatusBar statusBar1
private System.Windows.Forms.StatusBarPanel statusBarPanel1

private void InitializeComponent(


this.statusBar1.Location = new System.Drawing.Point(0, 328)
this.statusBar1.Name = "statusBar1"
this.statusBar1.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[

this.statusBarPanel1})
this.statusBar1.ShowPanels = true
this.statusBar1.Size = new System.Drawing.Size(672, 22)
this.statusBar1.TabIndex = 2
this.statusBar1.Text = "statusBar1"


this.statusBarPanel1.BorderStyle
System.Windows.Forms.StatusBarPanelBorderStyle.Raised
this.statusBarPanel1.Text = "Ready...."
this.statusBarPanel1.ToolTipText = "Test"

// ...



// Update the status panel's tex
private void button1_Click(object sender, System.EventArgs e

this.statusBarPanel1.Text = "Button clicked..."




Regards
Aravind



Ada said:
hi AC
i was thinking because the code, although it's the same, appear twice i
different method, C# compiler would do all the clean up automatically
no go
code doesn't even compile
err msg
C:\Form1.cs(694): The type or namespace name 'panel1' could not be foun
(are you missing a using directive or an assembly reference?the LOAD FORM method but it got destroyed when it exited LOAD FORM
when i click on another method which contained the same code, it looks fo the INSTANCE
in this case, of course, i think it's out of scope
this is the reason why i added all enchilada again
obvioulsy, something didn't go as plan
before create the new instance in the new method
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top