[Message Deleted]
-
Create your own CheckBox by inheriting from the CheckBox class and overriding the OnClick method. Just don't call the base classes OnClick method and you'll get the effect you want.
public class ReadOnlyCheckBox : CheckBox
{
protected override void OnClick(System.EventArgs e)
{
// Just don't call the base class OnClick method...
// base.OnClick(e);
}
}Put this in its own file in your project and compile it. When you do, you'll get a new ReadOnlyCheckBox in the Toolbox. Drag and drop to your form. Other than clicking, it'll work exactly like the normal CheckBox.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
It's a little more complicated than that, if you're going for what I suspect. I ran into this same problem a little while ago, and here's my solution.
-
It's a little more complicated than that, if you're going for what I suspect. I ran into this same problem a little while ago, and here's my solution.
-
Try it again... I was a bit out of it, and it took a few tries to get the link right... Heh
-
It's a little more complicated than that, if you're going for what I suspect. I ran into this same problem a little while ago, and here's my solution.
I checked out that link. If I understand what you're getting at, you're capturing the window message for button down and stuff, essentially just intercepting the messages and stopping them from being dispatched. We've both done the same thing but from different ends. Both methods havae their pros and cons. First, in my method, I'm not stopping the mouse message, just stopping the event from firing once the message is dispatched. The upside is it's very little code, being done in about a minute. The down side is that if you have multiple controls, you'd have to do this for each control. But, again on the upside, this makes the controls reusable in other applications without any kind of outside support, like another panel. In your method, you can use any controls you want, making the method quite flexible without having to modify any controls, save the panel control! The downside is that it's an all-or-nothing solution. You cannot turn off the click, or other events, for just some of the controls and leave it up for the rest. This could cause a problem if different control types have varying requirements for use of the mouse, or other events. The other downside to this method is embedding a child modifiedpanel into a larger modifiedpanel. If the larger container panel is "ReadOnly", the mous messages won't get down to the child modifiedpanel that you might want to NOT be "ReadOnly". The opposite situation does work though. The parent panel can be Read/Write while the child panel can be ReadOnly.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
I checked out that link. If I understand what you're getting at, you're capturing the window message for button down and stuff, essentially just intercepting the messages and stopping them from being dispatched. We've both done the same thing but from different ends. Both methods havae their pros and cons. First, in my method, I'm not stopping the mouse message, just stopping the event from firing once the message is dispatched. The upside is it's very little code, being done in about a minute. The down side is that if you have multiple controls, you'd have to do this for each control. But, again on the upside, this makes the controls reusable in other applications without any kind of outside support, like another panel. In your method, you can use any controls you want, making the method quite flexible without having to modify any controls, save the panel control! The downside is that it's an all-or-nothing solution. You cannot turn off the click, or other events, for just some of the controls and leave it up for the rest. This could cause a problem if different control types have varying requirements for use of the mouse, or other events. The other downside to this method is embedding a child modifiedpanel into a larger modifiedpanel. If the larger container panel is "ReadOnly", the mous messages won't get down to the child modifiedpanel that you might want to NOT be "ReadOnly". The opposite situation does work though. The parent panel can be Read/Write while the child panel can be ReadOnly.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007That's basically correct, with one correction. In order to avoid that last problem you mentioned, I run an entire form or parent container through an algorithm that specifies certain exceptions (Lock all controls except A, B, and C). The algorithm takes the entire tree or subtree of controls, and inserts those locked panels wherever needed such that they cover all controls except the ones listed as exceptions. So if control X has children A, B, and C, and we don't want to lock up B, it would leave X alone and lock up A and C separately. This of course assumes that container controls don't themselves need to be locked, so it's not quite foolproof.