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. Changing control rectangle color?

Changing control rectangle color?

Scheduled Pinned Locked Moved C#
graphicsquestion
7 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.
  • M Offline
    M Offline
    Megidolaon
    wrote on last edited by
    #1

    You know how some website login forms change the color of textboxes you left empty to red? I want to do that in my application. Basically after entering data you can click a "check" button that is supposed to highlight empty textboxes in red. I tried using a graphics object and draw rectangles above the textboxes, but it doesn't work well. Not the entire border is highlighted, but only the right and lower side.

    A R D V M 5 Replies Last reply
    0
    • M Megidolaon

      You know how some website login forms change the color of textboxes you left empty to red? I want to do that in my application. Basically after entering data you can click a "check" button that is supposed to highlight empty textboxes in red. I tried using a graphics object and draw rectangles above the textboxes, but it doesn't work well. Not the entire border is highlighted, but only the right and lower side.

      A Offline
      A Offline
      Adam R Harris
      wrote on last edited by
      #2

      Well, I haven't done that but I must ask, why not use an error provider? Just find the Error Provider[^] in your toolbox and drop one on your form. Then you can use something like this to set the error when they click 'check'. myErrorProvider.SetError(myTextBox, "Not Valid");

      If at first you don't succeed ... post it on The Code Project and Pray.

      1 Reply Last reply
      0
      • M Megidolaon

        You know how some website login forms change the color of textboxes you left empty to red? I want to do that in my application. Basically after entering data you can click a "check" button that is supposed to highlight empty textboxes in red. I tried using a graphics object and draw rectangles above the textboxes, but it doesn't work well. Not the entire border is highlighted, but only the right and lower side.

        R Offline
        R Offline
        Ravi Bhavnani
        wrote on last edited by
        #3

        See TextBox.BackColor[^].  You may also want to consider using the ErrorProvider[^] class. /ravi

        My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

        1 Reply Last reply
        0
        • M Megidolaon

          You know how some website login forms change the color of textboxes you left empty to red? I want to do that in my application. Basically after entering data you can click a "check" button that is supposed to highlight empty textboxes in red. I tried using a graphics object and draw rectangles above the textboxes, but it doesn't work well. Not the entire border is highlighted, but only the right and lower side.

          D Offline
          D Offline
          Dr Walt Fair PE
          wrote on last edited by
          #4

          Another possibility is to place an asterisk (*) in the text or color the boxes when the form is populated. Then in the Validating event, change the color, etc. if the result is valid. The color can be changed by setting the BackColor property, but you may need to refresh or Invalidate() the control to see the change.

          CQ de W5ALT

          Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software

          1 Reply Last reply
          0
          • M Megidolaon

            You know how some website login forms change the color of textboxes you left empty to red? I want to do that in my application. Basically after entering data you can click a "check" button that is supposed to highlight empty textboxes in red. I tried using a graphics object and draw rectangles above the textboxes, but it doesn't work well. Not the entire border is highlighted, but only the right and lower side.

            V Offline
            V Offline
            V 0
            wrote on last edited by
            #5

            if it is a website, I would do this in client side code instead of server code. (saves a round trip to the server) Add a validation function that is called on the onchange event for that control that will do some basic checking (empty fields, phone number formatting, etc...) and color the control accordingly. Alternatively you can skip the onchange event and put the validation when the form is submitted.

            V.

            1 Reply Last reply
            0
            • M Megidolaon

              You know how some website login forms change the color of textboxes you left empty to red? I want to do that in my application. Basically after entering data you can click a "check" button that is supposed to highlight empty textboxes in red. I tried using a graphics object and draw rectangles above the textboxes, but it doesn't work well. Not the entire border is highlighted, but only the right and lower side.

              M Offline
              M Offline
              Megidolaon
              wrote on last edited by
              #6

              It's not a website, it's a windows forms app. I'm currently changing the backcolor to red and forecolor to white (when you change the text, the color also changes back to normal) but that looks kinda awkward. If possible I'd like to use the more elegant way of just coloring the frame of the textbox/drawing a frame around it. How does the blinking look? It's quite possible that there'd be like 5 textboxes on a form which require input and all of them blinking at the same time would probably weird and confusing. I want a simple, yet obvious visual hint that there is something wrong.

              A 1 Reply Last reply
              0
              • M Megidolaon

                It's not a website, it's a windows forms app. I'm currently changing the backcolor to red and forecolor to white (when you change the text, the color also changes back to normal) but that looks kinda awkward. If possible I'd like to use the more elegant way of just coloring the frame of the textbox/drawing a frame around it. How does the blinking look? It's quite possible that there'd be like 5 textboxes on a form which require input and all of them blinking at the same time would probably weird and confusing. I want a simple, yet obvious visual hint that there is something wrong.

                A Offline
                A Offline
                Adam R Harris
                wrote on last edited by
                #7

                Then use the ErrorProvider, just run some tests. The ErrorProvider, see my previous reply, is a windows forms control so i dont really understand the

                Megidolaon wrote:

                It's not a website, it's a windows forms app.

                comment :^)

                If at first you don't succeed ... post it on The Code Project and Pray.

                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