Enabled look in a disabled control

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is it possible to make a disabled control (control.Enabled = false) to look
(just to look not to behave) like a enabled one ?
Thanks.

_____
Marco
 
You could derive a new class from a control and override the WndProc,
passing the message to the base class only if not disabled. However you will
have to take care of the drawing of the control if it get dirty, otherwise
the controls "disappears" from the screen.

using System;

namespace System.Windows.Forms
{
public class MyButton : Button
{
protected override void WndProc( ref Message m )
{
if( this.Enabled ) base.WndProc( ref m );
}
}
}
 
using System;

namespace System.Windows.Forms
{
public class MyButton : Button
{
private const int WM_PAINT = 0x000F;

protected override void WndProc( ref Message m )
{
if( this.Enabled )
{
base.WndProc( ref m );
}
else
{
if( ( m.Msg == WM_PAINT ) && !this.Enabled )
{
this.Enabled = true;
base.WndProc( ref m );
this.Enabled = false;
}
}
}
}
}
 

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

Back
Top