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. Visual Basic
  4. Custom Control

Custom Control

Scheduled Pinned Locked Moved Visual Basic
3 Posts 2 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
    Robert Breault
    wrote on last edited by
    #1

    I want to create a TextBox Control that will change the back colour when it gets focus and then reset the back colour when it leaves focus

    C 1 Reply Last reply
    0
    • R Robert Breault

      I want to create a TextBox Control that will change the back colour when it gets focus and then reset the back colour when it leaves focus

      C Offline
      C Offline
      Cliff Wellman
      wrote on last edited by
      #2

      Use the GotFocus() and LostFocus() methods of the TextBox control to change the background color. ... Private Sub TextBox1_GotFocus(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles TextBox1.GotFocus TextBox1.BackColor = System.Drawing.Color.Blue End Sub Private Sub TextBox1_LostFocus(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles TextBox1.LostFocus TextBox1.BackColor = System.Drawing.Color.White End Sub ...

      C 1 Reply Last reply
      0
      • C Cliff Wellman

        Use the GotFocus() and LostFocus() methods of the TextBox control to change the background color. ... Private Sub TextBox1_GotFocus(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles TextBox1.GotFocus TextBox1.BackColor = System.Drawing.Color.Blue End Sub Private Sub TextBox1_LostFocus(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles TextBox1.LostFocus TextBox1.BackColor = System.Drawing.Color.White End Sub ...

        C Offline
        C Offline
        Cliff Wellman
        wrote on last edited by
        #3

        If you want this functionality in a custom control here are the steps you need to follow: (from the documentation on Inheriting from Existing Windows Form Controls) 1) Create a Windows Executable or a Windows Control Library project. (in the end you'll want to use a Windows Control Library, but for my test I just created the control in a Windows Executable project) 2) From the project menu select Add Inherited Control. 3) Select Custom Control in the Add New Item dialog box. 4) Go into the code for your new control and modify it so that you are inheriting from the specific control (in our case TextBox). change Public Class MyColorTextBox Inherits System.Windows.Form.Control to Public Class MyColorTextBox Inherits System.Windows.Form.Textbox ... Now put in your code for the GotFocus() and LostFocus() events...as we did before. For my test I then put a TextBox control on the form of my test application. Then I went into the system generated code and changed the declaration of the Textbox to a MyColorTextBox. ie. change Me.TextBox1 = New Systems.Windows.Forms.TextBox to Me.TextBox1 = New WindowsApplication1.ColorTextBox Now what you really want to do is wrap your new control into a Windows Control Library so that you can just draw a MyColorTextBox on any form. But I'm not going to go into all of that here. Hopefully this is a good start for you.

        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