0

I wrote like this:

this.myTreeView.FullRowSelect = true;
this.myTreeView.Size = new System.Drawing.Size(170, 300);

and when I use this property myTreeView.Enabled = false, it becomes like this:

enter image description here

Shadowed only tree area, but not all control, how to fix this? (make all control been shadowed)

Romz
  • 1,437
  • 7
  • 36
  • 63
  • That's not what a standard TreeView control looks like. Surely you're using the DrawMode property? Make it look like a disabled treeview that doesn't use custom drawing and your user will stop complaining. – Hans Passant Sep 09 '12 at 21:57

2 Answers2

0

This is just an effect but the important thing is that it disable the whole control. Infact if you try for example, the scrollbar is also disabled. But you can try to achieve this effect using a dirty trick:

public class CostumizedTreeView : TreeView {
    Color defaultBackColor;
    public CostumizedTreeView( ) {
        defaultBackColor = BackColor;
    }

    public void Enable( bool Enabled ) {
        this.Enabled = Enabled;

        if ( !Enabled )
            BackColor = Color.LightGray;
        else
            BackColor = defaultBackColor;
    }
}

And when is disabled achieve this:

enter image description here


Else you can create your own customized control using DevExpress or Telerik Controls. For more info look here.

Community
  • 1
  • 1
Omar
  • 16,329
  • 10
  • 48
  • 66
0

What about:

.... Form()
{
this.InitializeComponent();

treeView1.EnabledChanged += (s, o) =>
{
    treeView1.BackColor = treeView1.Enabled ? Color.White : SystemColors.Control;
};

....

}
S3ddi9
  • 2,121
  • 2
  • 20
  • 34
  • I added like this `this.myTreeView.EnabledChanged += (s, o) =>...`, and I've got warning: `The code within the method 'InitializeComponent' is generated by the designer and should not be manually modified. Please remove any changes and try opening the designer again.` What am I doing wrong ? – Romz Sep 10 '12 at 13:41
  • 1
    Don't make the change in your .designer.cs file - there's a warning at the top of it that tells you not to change it. Make the change in your .cs file directly. – tomfanning Sep 10 '12 at 13:53
  • that's right .designer.cs file are generated automatically, so your code can be overridden, add the code at the constructor for example as the updated code @William – S3ddi9 Sep 10 '12 at 14:38