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. Make a button lose focus

Make a button lose focus

Scheduled Pinned Locked Moved C#
tutorialquestion
9 Posts 5 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.
  • S Offline
    S Offline
    sharpiesharpie
    wrote on last edited by
    #1

    Is it possible to make a button lose it's focus once a mouse has passed it? (i mean, if it's clicked and held down and then the mouse moves out of the button). for example, the buttons in Minesweeper are like that. so, is there any way to do so?

    C M 2 Replies Last reply
    0
    • S sharpiesharpie

      Is it possible to make a button lose it's focus once a mouse has passed it? (i mean, if it's clicked and held down and then the mouse moves out of the button). for example, the buttons in Minesweeper are like that. so, is there any way to do so?

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      Set the focus to something else.


      Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... "I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless." My website

      S 1 Reply Last reply
      0
      • C Colin Angus Mackay

        Set the focus to something else.


        Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... "I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless." My website

        S Offline
        S Offline
        sharpiesharpie
        wrote on last edited by
        #3

        but how would i know which button to set the focus to? (did you even look at minesweeper to see what i meant?)

        W 1 Reply Last reply
        0
        • S sharpiesharpie

          Is it possible to make a button lose it's focus once a mouse has passed it? (i mean, if it's clicked and held down and then the mouse moves out of the button). for example, the buttons in Minesweeper are like that. so, is there any way to do so?

          M Offline
          M Offline
          martin_hughes
          wrote on last edited by
          #4

          In Minewseeper they might look and act like buttons, but there's clearly some additional functionality built in, not to mention the actual Minesweeper "grid" itself. To emulate that, I think you're going to have to spend a bit of time developing your own custom control - although this will clearly take a bit more time, it will afford you much finer control (pun intended ;) )

          "It was the day before today.... I remember it like it was yesterday." -Moleman

          S 1 Reply Last reply
          0
          • M martin_hughes

            In Minewseeper they might look and act like buttons, but there's clearly some additional functionality built in, not to mention the actual Minesweeper "grid" itself. To emulate that, I think you're going to have to spend a bit of time developing your own custom control - although this will clearly take a bit more time, it will afford you much finer control (pun intended ;) )

            "It was the day before today.... I remember it like it was yesterday." -Moleman

            S Offline
            S Offline
            sharpiesharpie
            wrote on last edited by
            #5

            Well...i did make a custom control, a panel that has an array of rectangles in it into which i render images, but it was EXTREMELY flickery for some reason (even though i used a backbuffer) :/

            L 1 Reply Last reply
            0
            • S sharpiesharpie

              but how would i know which button to set the focus to? (did you even look at minesweeper to see what i meant?)

              W Offline
              W Offline
              Wjousts
              wrote on last edited by
              #6

              sharpiesharpie wrote:

              but how would i know which button to set the focus to?

              Don't set focus to another button. Set it to a panel, or a label, or anything else. Panels and labels are good because they don't show as focused.

              sharpiesharpie wrote:

              (did you even look at minesweeper to see what i meant?)

              Wow! Way to get pissy.

              1 Reply Last reply
              0
              • S sharpiesharpie

                Well...i did make a custom control, a panel that has an array of rectangles in it into which i render images, but it was EXTREMELY flickery for some reason (even though i used a backbuffer) :/

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #7

                In a situation with over one hundred controls, the obvious solution to flickering (and lack of performance about which you will complain later on) is the lightweight approach: forget Buttons, use a double-buffered Panel, draw everything yourself, and handle the necessary mouse events yourself. I guess that's how Microsoft did Minesweeper; they use 57 GDI objects, both in Beginners and in Expert mode, according to TaskInfo. :)

                Luc Pattyn


                try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }


                S 1 Reply Last reply
                0
                • L Luc Pattyn

                  In a situation with over one hundred controls, the obvious solution to flickering (and lack of performance about which you will complain later on) is the lightweight approach: forget Buttons, use a double-buffered Panel, draw everything yourself, and handle the necessary mouse events yourself. I guess that's how Microsoft did Minesweeper; they use 57 GDI objects, both in Beginners and in Expert mode, according to TaskInfo. :)

                  Luc Pattyn


                  try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }


                  S Offline
                  S Offline
                  sharpiesharpie
                  wrote on last edited by
                  #8

                  i did draw everything myself, i drew images on a panel and overrided the mouse movements and added a basic collision detection...but it did flicker :/

                  L 1 Reply Last reply
                  0
                  • S sharpiesharpie

                    i did draw everything myself, i drew images on a panel and overrided the mouse movements and added a basic collision detection...but it did flicker :/

                    L Offline
                    L Offline
                    Luc Pattyn
                    wrote on last edited by
                    #9

                    Hi, when a Panel does not contain any other Control, has double-buffering set up correctly, and has all its drawing in its Paint handler, the only way I can think of to get flickering is by having a bug in either your animation logic or your paint logic (unless you are showing/hiding other stuff on top of it of course). I have several apps that work this way, including a complex text editor; all work just fine, not a single glitch to be seen. As most often, my advice is to include code for logging/tracing so you can check things happen when they should, and more importantly in this case, dont happen when they should not. :)

                    Luc Pattyn


                    try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }


                    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