Control responding to mouse events while disabled?

  • Thread starter Thread starter joecool1969
  • Start date Start date
J

joecool1969

Apparently, when a textbox's Enabled property is set to false, it
doesn't respond to mouse events.

I have an app I an working on that I want to tell the user the value
in a textbox is currently invalid but could become valid if say a
flash drive was installed with the missing path/file. And I wanted to
use the MouseClick event to signal the app to recheck the resource to
see it is now available.

But I found that when the textbox's Enabled property is set to false,
the MouseClick event never fires.

Is there a way around this?
 
Apparently, when a textbox's Enabled property is set to false, it
doesn't respond to mouse events.

I have an app I an working on that I want to tell the user the value
in a textbox is currently invalid but could become valid if say a
flash drive was installed with the missing path/file. And I wanted to
use the MouseClick event to signal the app to recheck the resource to
see it is now available.

But I found that when the textbox's Enabled property is set to false,
the MouseClick event never fires.

Is there a way around this?

I don't think so. I'd put a Refresh button next to it.


Armin
 
Apparently, when a textbox's Enabled property is set to false, it
doesn't respond to mouse events.

I have an app I an working on that I want to tell the user the value
in a textbox is currently invalid but could become valid if say a
flash drive was installed with the missing path/file. And I wanted to
use the MouseClick event to signal the app to recheck the resource to
see it is now available.

But I found that when the textbox's Enabled property is set to false,
the MouseClick event never fires.

Is there a way around this?

Yes. First of all, here's a Panel-derived custom control that is fully
transparent (Panel.BackColor = Color.Transparent doesn't cut it -
you'll see why if you try it):

public class TransparentPanel : Panel
{
protected override CreateParams CreateParams
{
get
{
var result = base.CreateParams;
result.ExStyle |= 0x00000020; // WS_EX_TRANSPARENT
return result;
}
}

protected override void OnPaintBackground(PaintEventArgs e)
{
// Paint nothing
}
}

Now just stick it on top of your textbox (simplest way - data-bind
Location & Size properties of panel to corresponding properties of
textbox, one-way), and make the panel hidden by default. Show it when
textbox is disabled and catch mouse events on it; hide it again when
textbox is enabled.
 
Apparently, when a textbox's Enabled property is set to false, it
doesn't respond to mouse events.

I have an app I an working on that I want to tell the user the value
in a textbox is currently invalid but could become valid if say a
flash drive was installed with the missing path/file. And I wanted to
use the MouseClick event to signal the app to recheck the resource to
see it is now available.

But I found that when the textbox's Enabled property is set to false,
the MouseClick event never fires.

Is there a way around this?

Besides the other suggestions, you could set the textbox's ReadOnly
property to True instead of disabling it. That makes it look
different than disabled, but does allow events.
 
Besides the other suggestions, you could set the textbox's ReadOnly
property to True instead of disabling it.  That makes it look
different than disabled, but does allow events.

While the custom usercontrol option was elegant, your suggestion was
by far the easiest and works just fine. I can't even tell the
difference in appearance of the textbox when run on Vista.

Thanks.
 
While the custom usercontrol option was elegant, your suggestion was
by far the easiest and works just fine. I can't even tell the
difference in appearance of the textbox when run on Vista.

Switch to the Classic theme and you'll see it easily (the greyed-out
background and text). In XP and Vista themes, only the text and the
border are greyed out, so you may not spot the difference unless you
have some text in the textbox.
 
Back
Top