Hi Dan:
I would like to change the image of indeterminate state of a checkbox in
datagridview from green square to red check.
First of all, this "green square" is derived from used (default in Widows XP?) Visual Style. You may see it i.ex.: by
changing in VS2005:
Project->YourAppProperties ->Application: Enable XP visual styles; if unchecked, application works in classical windows
style
("But, there is no spoon..." green square). Any user may change windows style by changing desktop properties...
Can anybody tell me how to do it? Thanks a lot.
If you want to change/control it anyway, I prefer this method (paste to form's with chcekbox1 code):
'***************************************************************************************
Dim CursorOverCheckbox As Boolean = False
Private Sub CheckBox1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox1.MouseEnter
CursorOverCheckbox = True
End Sub
Private Sub CheckBox1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox1.MouseLeave
CursorOverCheckbox = False
End Sub
Private Sub CheckBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles
CheckBox1.Paint
'...
If Me.CheckBox1.CheckState = CheckState.Indeterminate Then
If Me.CursorOverCheckbox Then
Static xhot As New Bitmap("c:\tmp\xhot.bmp")
e.Graphics.DrawImage(xhot, 0, 0)
Else
Static x As New Bitmap("c:\tmp\x.bmp")
'Static x As Bitmap = LoadResPicture("WindowsApplication8.x.bmp")
e.Graphics.DrawImage(x, 0, 0)
End If
End If
'...
End Sub
'***************************************************************************************
Where c:\tmp\x.bmp and c:\tmp\xhot.bmp are two small (about 16x16 pixels) pictures:
c:\tmp\x.bmp is normal chcekbox with indeterminate state
c:\tmp\xhot.bmp is for indeterminate state when cursor is over checkbox;
Prepare this small pictures, as you wish - each for one state, you want to change.
(I used PrintScreen and CTRL+V in Paint.exe, to prepare them...)
Finally, when You finish all images You may add them to the resources and load i.ex. with main form load event...
(here's howto use resources:
http://support.microsoft.com/kb/q319291/)
or load them with function like this:
'***************************************************************************************
Function LoadResPicture(ByVal strResName As String) As Image
Dim _assembly As [Assembly]
Dim _imageStream As Stream
Try
_assembly = [Assembly].GetExecutingAssembly()
_imageStream = _assembly.GetManifestResourceStream(strResName)
Return New Bitmap(_imageStream)
Catch ex As Exception
MessageBox.Show("Resource wasn't found!", "Error")
End Try
Return Nothing
End Function
'***************************************************************************************
and lines like:
Static x As New Bitmap("c:\tmp\x.bmp")
replace with :
Static x As Bitmap = LoadResPicture("WindowsApplication8.x.bmp")
I hope this helps.
Regards:
Marcin Dzióbek