Solved

Setting NumericUpDown to Read Only has no effect.

Posted on 2009-03-30
4
280 Views
Last Modified: 2013-11-25
I need to keep the NumericUpDown control set to enabled for visual purposes and I have set the readonly property to true.  It still changes the value.  A msgbox appears since I am able to test for the ReadOnly property being true and I exist the ValueChanged procedure, but it still changes the value.  How can I prevent this?
VB Express 2008
0
Comment
Question by:GarySB
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 24020396
have a look at http://www.emoreau.com/Entries/Articles/2005/07/Colors-of-disabled-controls.aspx.

I have overwritten many controls (but not the NumericUpDown) to set the wanted colors when controls are disabled.
0
 

Author Comment

by:GarySB
ID: 24021404
Thank You, but I was not able to apply it.  Unless a reasonable amount of code can be found I will have to change my contorls to a label which I wanted to avoid.
0
 
LVL 48

Accepted Solution

by:
jpaulino earned 125 total points
ID: 24023038
You can create your class and simulate the Readonly Property (in the other controls) without changing the colors.
Create a new class and paste this code (check code snippet) and build tthe application. You will have a new control in the toolbox that you can use this way:

Me.ReadOnlyNumericUpDown1.ReadOnly = True

Class ReadOnlyNumericUpDown
    Inherits NumericUpDown
 
    Private m_ReadOnly As Boolean
    Shadows Property [ReadOnly]() As Boolean
        Get
            Return m_ReadOnly
        End Get
        Set(ByVal value As Boolean)
            m_ReadOnly = value
        End Set
    End Property
 
    Public Overrides Sub UpButton()
        If Not Me.ReadOnly Then
            MyBase.UpButton()
        End If
    End Sub
 
    Public Overrides Sub DownButton()
        If Not Me.ReadOnly Then
            MyBase.DownButton()
        End If
    End Sub
 
    Protected Overrides Sub OnKeyDown(ByVal e As System.Windows.Forms.KeyEventArgs)
        If Not Me.ReadOnly Then
            MyBase.OnKeyDown(e)
        Else
            e.SuppressKeyPress = True
        End If
    End Sub
 
End Class

Open in new window

0
 

Author Closing Comment

by:GarySB
ID: 31564386
It Works Great!!! Thank You
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question