ToolStripStatusLabel Bug
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: ToolStripStatusLabel Bug

  1. #1
    Join Date
    May 2008
    Posts
    36

    ToolStripStatusLabel Bug

    I have the most annoying bug appearing in the framework thats doing my head in.
    When ever my form is displayed and it appears behind another window a ToolStripStatusLabel in the bottom left does not display properly instead it appears as a black box, this has nothing to do with the BackColor, see pic, but at the same time another ToolStripStatusLabel on another status bar is displayed properly. I have tried timers which remove the label and insert a new one but to no avail.

    I have 2 pics the first shows it as it normally occurs the second after I change the BackColor property. The second really shows up the bug.

    OS is Win7, framework is 4.0 but am compiling to 2.0 (just tested with compiling to 4.0 and same story)
    I have also had this problem before running 3.0 on Win XP.

    Has anyone else encountered this before? Or better still a fix?

    Thanks,
    Ger.
    Attached Images Attached Images   

  2. #2
    Join Date
    Jul 2010
    Posts
    82

    Thumbs up Re: ToolStripStatusLabel Bug

    Its a paint issue. Did you try toolstriplabel.Refresh() - I have seen this when I tried to run my Win XP app with forms and standard controls in it , it worked fine, but on a Win 2K it showed black. I guess its how Win 2K sees it. Did you try Refresh()? Please let me know.

  3. #3
    Join Date
    Jun 2008
    Posts
    2,477

    Re: ToolStripStatusLabel Bug

    Refresh() (or preferably Invalidate()) should not be needed; the controls repaint themselves when those properties are changed. Are you painting those controls yourself or are they standard library controls (are you handling/overriding the paint method)?

  4. #4
    Join Date
    May 2008
    Posts
    36

    Re: ToolStripStatusLabel Bug

    Quote Originally Posted by CuteAssistant View Post
    Its a paint issue. Did you try toolstriplabel.Refresh().
    Ye I tried that, no luck.

    I found a horrible solution:
    Code:
            private void MainForm_Load(object sender, EventArgs e)
            {
                timPaint.Tick += new EventHandler(timPaint_Tick);
                timPaint.Interval = 300;
                timPaint.Start();
            }
    
            System.Windows.Forms.Timer timPaint = new System.Windows.Forms.Timer();
            ToolStripLabel lbl = new ToolStripLabel(String.Empty);
            void timPaint_Tick(object sender, EventArgs e)
            {
                if (!stsStripLeft.Items.Contains(lbl))
                {
                    stsStripLeft.Items.Add(lbl);
                    timPaint.Stop();
                }
                    //I did try to remove the lbl here but it seems that if the lbl is removed while
                    //that section of the form is not visible ie under another window it stays black.
                    //thankfully the lbl has no visible effect so I think it best to leave it in.
            }
    If someone understands why this hack works and can devise a smarter way please let me know.
    Last edited by gleesonger; July 19th, 2010 at 08:43 PM. Reason: Code updated

  5. #5
    Join Date
    May 2008
    Posts
    36

    Re: ToolStripStatusLabel Bug

    Quote Originally Posted by BigEd781 View Post
    Refresh() (or preferably Invalidate()) should not be needed; the controls repaint themselves when those properties are changed. Are you painting those controls yourself or are they standard library controls (are you handling/overriding the paint method)?
    No im not doing anything unusual, its a standard toolstriplabel thats been added through the designer, all of the parent controls are standard and the paint control is not overriden and as far as I remember I hant gone near the designer code though that shouldn't matter.

  6. #6
    Join Date
    Jul 2010
    Posts
    82

    Re: ToolStripStatusLabel Bug

    How is it in design time? Its clearly the OS or your system that not able to display it properly. I have seen a similar problem before as well. Ah, of all the ways a timer is used...it does help sometimes with hacks like this. Is it in Win XP or Win 2K?

  7. #7
    Join Date
    May 2008
    Posts
    36

    Re: ToolStripStatusLabel Bug

    While debugging its fine, but then the same conditions are not, as whenever I run it from the ide the form is always displayed on top, however if I run the same exe (\Debug\application.exe) directly the bug occurs. During design time no problems are seen.
    Both the debug and release version of the app display the same problem.

    At the moment I'm running csharp express edition 2010 compiling to version 2.0 running on Win7 32bit, but I've seen this bug occur when I compiled it to version 4.0 on the same machine, and also before when working with another app when I was then running csharp express edition 2008 on Win XP compiling to all version.

    I havn't a clue why this hack works but it does, and as of yet I havn't seen the bug again. In fact if I'm quick enough with the mouse and give top focus to the app I catch a glimpse of the black box, just before the timer fires and the extra toolstipitem added.

  8. #8
    Join Date
    Nov 2013
    Posts
    1

    Re: ToolStripStatusLabel Bug

    I had the same situation trying to refresh the toolstripstatuslabel. Whenever I wanted the toolstripstatuslabel to display a different message it only displayed the last one but I knew my code was correct except that it apparently was doing it too fast. In order to solve it implemented/used the this.refresh() everytime a new value was passed to the toolstripstatuslabel. For example,

    if (Result != DialogResult.Cancel)
    {
    // MessageBox.Show("No file has been chosen in order to process accordingly.", "Open error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    try
    {
    StreamReader myStreamReader = new StreamReader(openFileDialog1.FileName);
    if (myStreamReader != null)
    {
    using (myStreamReader)
    {
    commondisable();
    toolStripStatusLabel1.BackColor = Color.Salmon;
    toolStripStatusLabel1.Text = "Please wait while reading from: " + openFileDialog1.FileName;
    this.Refresh();

    toolStripProgressBar1.Value = 0; // reset progressbar
    var myLineCount = File.ReadAllLines(openFileDialog1.FileName).Length; // check line length of file to determine progressbar maximum
    toolStripProgressBar1.Maximum = myLineCount;

    listView1.Items.Clear();

    string[] myItems = new string[12];
    // Insert code to read the stream here.
    String myLineRead;
    myLineRead = myStreamReader.ReadLine();
    while (myLineRead != null)
    {
    if (myLineRead.Substring(0, 1) == "0")
    {
    textBox3.Text= myLineRead.Substring(1, 9);
    textBox4.Text = myLineRead.Substring(10, 8);
    }
    else if (myLineRead.Substring(0, 1) == "1")
    {
    if (myLineRead.Length > 200)
    {
    myItems[11] = myLineRead.Substring(190, 540).Trim();
    }
    //In this example an array of three items is added to a three column listview
    myItems[0] = myLineRead.Substring(0, 1);
    myItems[1] = myLineRead.Substring(1, 5);
    myItems[2] = myLineRead.Substring(6, 9);
    myItems[3] = myLineRead.Substring(15, 60);
    myItems[4] = myLineRead.Substring(75, 1);
    myItems[5] = myLineRead.Substring(76, 9);
    myItems[6] = myLineRead.Substring(85, 60);
    myItems[7] = myLineRead.Substring(145, 12);
    myItems[8] = myLineRead.Substring(157, 20);
    if (myLineRead.Substring(177, 1) == " ") //Client(Y/N)
    {
    myItems[9] = "N";
    }
    else
    {
    myItems[9] = myLineRead.Substring(177, 1);
    }
    if (myLineRead.Substring(178, 12) == " ")
    {
    myItems[10] = "";
    }
    else
    {
    myItems[10] = myLineRead.Substring(178, 12);
    }
    ListViewItem lvi = new ListViewItem(myItems);
    listView1.Items.Add(lvi);
    }
    else if (myLineRead.Substring(0, 1) == "2")
    {
    textBox5.Text = myLineRead.Substring(10, 5);
    textBox6.Text = myLineRead.Substring(15, 12);
    }
    myLineRead = myStreamReader.ReadLine();
    toolStripProgressBar1.Value += 1;
    }
    }
    toolStripStatusLabel1.BackColor = Color.FromArgb(128, 255, 128);
    toolStripStatusLabel1.Text = "Completed reading file " + openFileDialog1.FileName;
    this.Refresh();

    myStreamReader.Close();
    panel2.Visible = true;
    label3.Visible = true;
    textBox3.Visible = true;
    label4.Visible = true;
    textBox4.Visible = true;
    label5.Visible = true;
    textBox5.Visible = true;
    label6.Visible = true;
    textBox6.Visible = true;
    textBox7.Visible = false;
    textBox7.Text = string.Empty;

    fileWasOpened = true;
    somethingChanged = false;
    }
    }
    catch (Exception ex)
    {
    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
    }
    }

  9. #9
    Join Date
    Dec 2013
    Posts
    1

    Re: ToolStripStatusLabel Bug

    Are you painting those controls yourself or are they standard library controls are you handling/overriding the paint method?




    -------------------------------
    Smile PlzZZzzz…(Usman Malik)…!!!
    in post

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center