Display in Night Mode

  • Thread starter Thread starter Maddy
  • Start date Start date
M

Maddy

I am writing a windowsform application which has to be used in both
day and night environments. In the night, the room is dark and all
controls need to be dimmed / subdued. Is there any control which can
help me do this. Or how do I do it?
Thank
Nitin
 
Hi Maddy,

once i had a fellow developer who had
problems with his eyes in bright rooms
and i wrote this for him. It modifies the
displays gamm ramp values and makes
it very dark. It is written in VB6 but it
should be n match to move it to C# for
you:

Private DeviceRampDefault(0 To 255, 0 To 2) As Integer
Private AdjustedDeviceRamp(0 To 255, 0 To 2) As Integer
Private Declare Function GetDeviceGammaRamp Lib "gdi32" (ByVal hdc As Long,
lpv As Any) As Long
Private Declare Function SetDeviceGammaRamp Lib "gdi32" (ByVal hdc As Long,
lpv As Any) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory"
(Destination As Any, Source As Any, ByVal Length As Long)

Private Sub CheckASGRSetGammaRamp_Click()
If Me.CheckASGRSetGammaRamp.Value = Checked Then
SetDarkGammaRamp
Else
SetDeviceGammaRamp Me.hdc, DeviceRampDefault(0, 0)
End If
End Sub

Private Sub commandASGRExit_Click()
mnuExit_Click
End Sub

Private Sub Form_Load()
Me.Caption = App.ProductName & " " & App.Major & "." & App.Minor
GetDeviceGammaRamp Me.hdc, DeviceRampDefault(0, 0)
End Sub

Private Sub Form_Unload(Cancel As Integer)
If Me.CheckASGRRestoreOnExit.Value = Checked Then
SetDeviceGammaRamp Me.hdc, DeviceRampDefault(0, 0)
End If
End Sub

Private Sub mnuAbout_Click()
Dim HelpMessage As String

HelpMessage = App.ProductName & " " & App.Major & "." & App.Minor & vbCrLf
_
& "by Kerem Gümrükcü" & vbCrLf _
& "Contact: (e-mail address removed)"

MsgBox HelpMessage, vbOKOnly Or vbInformation Or vbApplicationModal,
App.ProductName & " " & App.Major & "." & App.Minor

End Sub
Private Function SetDarkGammaRamp()
Dim iItr As Integer
Dim lVal As Long
For iItr = 0 To 255
lVal = IntToLng(DeviceRampDefault(iItr, 0))
AdjustedDeviceRamp(iItr, 0) =
LngToInt(IntToLng(DeviceRampDefault(iItr, 0)) / 2)
AdjustedDeviceRamp(iItr, 1) =
LngToInt(IntToLng(DeviceRampDefault(iItr, 1)) / 2)
AdjustedDeviceRamp(iItr, 2) =
LngToInt(IntToLng(DeviceRampDefault(iItr, 2)) / 2)
Next iItr

SetDeviceGammaRamp Me.hdc, AdjustedDeviceRamp(0, 0)

End Function
Private Sub mnuExit_Click()
Unload Me
End Sub

Public Function IntToLng(IntVal As Integer) As Long
CopyMemory IntToLng, IntVal, 2
End Function
Public Function LngToInt(Value As Long) As Integer
CopyMemory LngToInt, Value, 2
End Function

--
 
I am writing a windowsform application which has to be used in both
day and night environments. In the night, the room is dark and all
controls need to be dimmed / subdued. Is there any control which can
help me do this. Or how do I do it?
Thank
Nitin

Hi,

There is nothing like that in the framework.

You can customize your window desktop in such a way that it displays
nicerly @ nights.
What I do not know is how you can change the theme of the windows
desktop from .NET

Alternately there are third party frameworks (like infragistics) that
allow the use of Skins (just like asp.net) in windows. This will only
affet your application
 
Thanks for all the help. I am just starting to learn c# using a
project. Used Delphi earlier which had a component for this. Wont
waste time searching for a component now. Will think of something.
thanks.
 
Back
Top