Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. [Message Deleted]

[Message Deleted]

Scheduled Pinned Locked Moved C#
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    R_L_H
    wrote on last edited by
    #1

    [Message Deleted]

    D I 2 Replies Last reply
    0
    • R R_L_H

      [Message Deleted]

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • R R_L_H

        [Message Deleted]

        I Offline
        I Offline
        Ian Shlasko
        wrote on last edited by
        #3

        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.

        R D 2 Replies Last reply
        0
        • I Ian Shlasko

          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.

          R Offline
          R Offline
          R_L_H
          wrote on last edited by
          #4

          [Message Deleted]

          I 1 Reply Last reply
          0
          • R R_L_H

            [Message Deleted]

            I Offline
            I Offline
            Ian Shlasko
            wrote on last edited by
            #5

            Try it again... I was a bit out of it, and it took a few tries to get the link right... Heh

            1 Reply Last reply
            0
            • I Ian Shlasko

              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.

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              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 1 Reply Last reply
              0
              • D Dave Kreskowiak

                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 Offline
                I Offline
                Ian Shlasko
                wrote on last edited by
                #7

                That'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.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups