Results 1 to 12 of 12

Thread: enabling / disabling the controls

  1. #1

    Thread Starter
    Hyperactive Member kuldevbhasin's Avatar
    Join Date
    Mar 2008
    Location
    Mumbai, India
    Posts
    473

    enabling / disabling the controls

    hi...
    i have this function to enable disable the controls on a form....

    Code:
     Private Sub EnableDisableAll(ByVal xType As Boolean)
            Dim ctl As Control
            For Each ctl In Me.Controls
                If TypeOf ctl Is TextBox Then
                    ctl.Enabled = xType
                    ctl.BackColor = Color.White
                    ctl.ForeColor = Color.Red
                    'ctl.Font = New Font(mFontName, mFontSize, mFontStyle)
                ElseIf TypeOf ctl Is ComboBox Then
                    ctl.Enabled = xType
                    'ctl.Font = New Font(mFontName, mFontSize, mFontStyle)
                ElseIf TypeOf ctl Is DateTimePicker Then
                    ctl.Enabled = xType
                ElseIf TypeOf ctl Is CheckBox Then
                    ctl.Enabled = xType
                    '    ctl.DataBindings.Clear()
                End If
            Next
    
        End Sub
    everything fine ...but when the controls r disabled it shows in the dull color. can i change the color ? as u can see i have given the command to change the forcolor to red to textbox but it still shows in dull greay... i dont want it to be enabled as i am using this to just give a view of records....the back color is changing to white but not the forecolor.....is there any thing more to be done...or any better way so as the items remain enabled but i dont allow the changes to be done....

    pls. guide...thankx

  2. #2
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,834

    Re: enabling / disabling the controls

    You can go the Locked Control of the Property. The locked Property wont grey the control. The user can able to copy the items from the control
    Please mark you thread resolved using the Thread Tools as shown



    www.techreceipe.tk


  3. #3

    Thread Starter
    Hyperactive Member kuldevbhasin's Avatar
    Join Date
    Mar 2008
    Location
    Mumbai, India
    Posts
    473

    Re: enabling / disabling the controls

    great...that seems a much better idea....let me try it and get back ....thankx a lot

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    104,957

    Re: enabling / disabling the controls

    Quote Originally Posted by danasegarane View Post
    You can go the Locked Control of the Property. The locked Property wont grey the control. The user can able to copy the items from the control
    The Locked property has no effect at run time. It simply prevents you inadvertently moving a control at design time.

    Presumably you mean ReadOnly, but that only applies to TextBoxes.

    The reason that this is not catered for is because it goes against Windows UI design guidelines. If a control looks like it accepts input then the user has the right to expect it to accept input. Controls that look enabled but aren't are confusing to the user and should be avoided. If you want to ignore thes guidelines then you would probably have to trap and drop the appropriate Windows messages by overriding the controls WndProc method.

  5. #5

    Thread Starter
    Hyperactive Member kuldevbhasin's Avatar
    Join Date
    Mar 2008
    Location
    Mumbai, India
    Posts
    473

    Re: enabling / disabling the controls

    hey...i cant get the ctl.locked option ?? how do i do that ?? pls. help
    thankx

  6. #6
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,834

    Re: enabling / disabling the controls

    Quote Originally Posted by jmcilhinney View Post
    The Locked property has no effect at run time. It simply prevents you inadvertently moving a control at design time.

    Presumably you mean ReadOnly, but that only applies to TextBoxes.

    The reason that this is not catered for is because it goes against Windows UI design guidelines. If a control looks like it accepts input then the user has the right to expect it to accept input. Controls that look enabled but aren't are confusing to the user and should be avoided. If you want to ignore thes guidelines then you would probably have to trap and drop the appropriate Windows messages by overriding the controls WndProc method.
    oh my ignorance . I was trying to differentiate between read only and enabled.

    Jhon :
    I think it is true about the read only ?
    The locked Property wont grey the control. The user can able to copy the items from the control
    Please mark you thread resolved using the Thread Tools as shown



    www.techreceipe.tk


  7. #7
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    104,957

    Re: enabling / disabling the controls

    Quote Originally Posted by danasegarane View Post
    oh my ignorance . I was trying to differentiate between read only and enabled.

    Jhon :
    I think it is true about the read only ?
    I believe that Locked was a VB6 thing. As I said, ReadOnly applies to TextBoxes or, more correctly, TextBoxBase objects only. It will grey the background but not the text and the background colour can be changed, unlike when disabling.

  8. #8

    Thread Starter
    Hyperactive Member kuldevbhasin's Avatar
    Join Date
    Mar 2008
    Location
    Mumbai, India
    Posts
    473

    Re: enabling / disabling the controls

    thankx jmc but i cant find the ctl.readonly property too...and about the WndProc method ....i dont want to mess up anything....as i dont know about it....it seems to be doing something to the main setting .....i am not an expert so i feel i should not mess up with the settings of the system......

    how do i set the readonly prop. ?
    i can set the readonly prop. to each of the textbox by typing the individual name but not as the above eg. any particular reason ??
    thankx

  9. #9
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    104,957

    Re: enabling / disabling the controls

    Quote Originally Posted by kuldevbhasin View Post
    thankx jmc but i cant find the ctl.readonly property too...and about the WndProc method ....i dont want to mess up anything....as i dont know about it....it seems to be doing something to the main setting .....i am not an expert so i feel i should not mess up with the settings of the system......

    how do i set the readonly prop. ?
    i can set the readonly prop. to each of the textbox by typing the individual name but not as the above eg. any particular reason ??
    thankx
    I think I may have mentioned one or twice that ReadOnly applies only to TextBoxes. It's not a member of the Control class so you can't set it on a Control reference. It's a member of the TextBoxBase class so you can only set it on a reference of type TextBoxBase or a type that inherits TextBoxBase.

    Trapping Windows messages is going to require you to either create your own custom controls by inheriting the standard control classes and then overriding the WndProc method, or else inheriting the NativeWindow class and then hooking the existing controls. Neither is super-advanced but neither is trivial either. You'll also have to use some trial-and-error to determine the appropriate Windows messages to drop. Basically you'd be intercepting messages sent from the OS to the control so the control would never know that the user had clicked on it, pressed a key in it or whatever.

  10. #10
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Re: enabling / disabling the controls

    Just out of curiousity, is this form also used for the actual editing of records? If not, then just use labels. If it is, and you don't want to play around with WndProc, then just create a method called controlentered and bind the Enter event of every textbox to this method. When it fires, just redirect the the focus, like:

    Code:
    Private Sub ControlEntered(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.Enter, TextBox2.Enter, TextBox3.Enter
        Button1.Select()
    End Sub

  11. #11

    Thread Starter
    Hyperactive Member kuldevbhasin's Avatar
    Join Date
    Mar 2008
    Location
    Mumbai, India
    Posts
    473

    Re: enabling / disabling the controls

    ya..the same form is being used for edditing and adding too

  12. #12
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Re: enabling / disabling the controls

    Alright, so take my method and include a boolean class member called readOnly, set it to true or false accordingly and modify the method as such:

    If readOnly Then Button1.Select()

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width