Thomas Ayoub
Thomas Ayoub

Reputation: 29431

Why is my button state inconsistant?

In my application I've 3 ways to browse local data:

Theses 3 controls inherits from a base class :

Theses 3 ones inherits from the same base : DataBrowser. This class has a toolStrip (toolStrip1) which has a button to load data (loadToolStripButton). I want to disable this button every time the reader of my application is busy, which I do like so:

protected DataBrowser()
{
    InitializeComponent();

    OpenFiles.Instance.ReaderStatus += ReaderStatus;
    //...
}
//...
protected void ReaderStatus(ReadStatusEventArgs e)
{
    loadToolStripButton.Enabled = (e.Status == ReadStatus.Ready);
}

The event is triggered normally and the button is enabled/disabled normally both in the OpenFileControlUI and the FileFilterControlUI but with the RecentlyOpenedFilesUI the button is not disabled whereas the debugger tells me it is disabled.


I've added a MessageBox to show the item state using : MessageBox.Show("The button is :" + (loadToolStripButton.Enabled ? "Enabled" : "Disabled"));

This is the result with the two working controls:

working messagebox

And this it the non working one (you can see that the button is not disabled as it should):

non working one


What bugs me is that this is:

It doesn't fix this bug.

Simple question : How can I fix this?

Edit

Here's where I call it:

protected void ReaderStatus(ReadStatusEventArgs e)
{
    loadToolStripButton.Enabled = (e.Status == ReadStatus.Ready);
    MessageBox.Show("The button is :" + (loadToolStripButton.Enabled ? "Enabled" : "Disabled"));
}

And here's the DataBrowser.Designer.cs file (I kept only part about this stupid button):

partial class DataBrowser
{
    /// <summary> 
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.IContainer components = null;

    
    #region Component Designer generated code

    /// <summary> 
    /// Required method for Designer support - do not modify 
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
        this.components = new System.ComponentModel.Container();
        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(DataBrowser));
        this.toolStrip1 = new System.Windows.Forms.ToolStrip();
        this.loadToolStripButton = new System.Windows.Forms.ToolStripButton();
        this.toolStrip1.SuspendLayout();
        this.SuspendLayout();
        // 
        // toolStrip1
        // 
        this.toolStrip1.CanOverflow = false;
        this.toolStrip1.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden;
        this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
        this.loadToolStripButton});
        this.toolStrip1.Location = new System.Drawing.Point(0, 0);
        this.toolStrip1.Name = "toolStrip1";
        this.toolStrip1.RenderMode = System.Windows.Forms.ToolStripRenderMode.System;
        this.toolStrip1.Size = new System.Drawing.Size(216, 25);
        this.toolStrip1.TabIndex = 4;
        this.toolStrip1.Text = "toolStrip1";
        // 
        // loadToolStripButton
        // 
        this.loadToolStripButton.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right;
        this.loadToolStripButton.Image = global::Sakura.UI.DataBrowsing.Properties.Resources.FormRunHS;
        this.loadToolStripButton.ImageTransparentColor = System.Drawing.Color.Magenta;
        this.loadToolStripButton.Name = "loadToolStripButton";
        this.loadToolStripButton.Size = new System.Drawing.Size(53, 22);
        this.loadToolStripButton.Text = "Load";
        this.loadToolStripButton.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
        this.loadToolStripButton.TextImageRelation = System.Windows.Forms.TextImageRelation.TextBeforeImage;
        this.loadToolStripButton.Click += new System.EventHandler(this.loadToolStripButton_Click);
        // 
        // DataBrowser
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.Controls.Add(this.toolStrip1);
        this.Name = "DataBrowser";
        this.toolStrip1.ResumeLayout(false);
        this.toolStrip1.PerformLayout();
        this.ResumeLayout(false);
        this.PerformLayout();

    }

    #endregion

    protected System.Windows.Forms.ToolStrip toolStrip1;
    protected System.Windows.Forms.ToolStripButton loadToolStripButton;

}

Upvotes: 3

Views: 98

Answers (1)

Thomas Ayoub
Thomas Ayoub

Reputation: 29431

Ok I did a big cleaning:

  1. Right click on Solution => Clean Solution;
  2. Killed VS;
  3. Deleted ALL STUPID FILES using find . -iname "bin" -type d -print0|xargs -0 rm -r -- and find . -iname "obj" -type d -print0|xargs -0 rm -r -- from my preferred console;
  4. Shutdown the computer;
  5. Took another coffee;
  6. Restart Windows;
  7. Restart VS;
  8. Enjoyed the working code.

Side note: IF ANYONE FROM THE VS DEV TEAM READ THIS, PLEASE, MAKE Clean Solution CLEAN THE SOLUTION FOR REAL!

Upvotes: 2

Related Questions