I am building a custom property page for a user control, and would like to add to the form a custom color selector which is same as used on the stock Color Property Page (see attached JPG)
Thanks for the reply, ideally I am trying to find out if this "control" is available any where, as I see it used on a number of thirdpartt controls i.e TrueDBGrid etc.
Ideally I'd like a complete match, with images in ListBox as in pic, I may develop one using ListView (Easier with images), but was hoping to save some time, if this was available anywhere
npd, I think this is possible in VB6. I know for a fact it is very easy in VB.NET. Let me see if I can source one of my examples about this in VB 6, for you, else I'll make one in VB.NET and make it compatible with VB 6, and explain to you how to use it
Mine is not so pretty as your shown picure, but it is still pretty funky ( I think so )
What happens with my project is that it overrides the standard listbox in order to display the system colours ( that you want ). How the list displays them is, with each colour, the item's background is that associated colour.
Have a look at it, it does work, but if it is not what you wanted, or if you wanted something a bit more funky, I'll see what I can come up with - just note, I have very limited time these days, so I'll try my best for you
Have fun!
Hannes
Last edited by HanneSThEGreaT; June 14th, 2010 at 05:44 AM.
Not quite the same, but not bad either. Don't know if that's what he wabted, bit I say it looks good.
I like API juggling.
Now we would simply have to do a color change/edit routine, say, in the click or doubleclick event of the listbox.
Yip, not quite the same, I'm also a bit disappointed. It isn't what I intended, hopefully I can find a way to add the pictures - that will look quite funky. Time is a problem these days for me, as some may know. Watch this space !
Option Explicit
' cdlCFPrinterFonts &H2
' Save File Options
'&H2 - Forces a warning before overwriting a file
'&H8 - Stops default directory from changing
'&H200 - more than one file can be selected.
'&H1000 - This makes it so the file must exist.
'&H2000 - This warns the user before creating a new file.
Private Sub cmdOpen_Click()
' CancelError is True.
On Error GoTo ErrHandler
CommonDialog1.InitDir = App.Path
' Set Flags
CommonDialog1.Flags = cdlOFNAllowMultiselect Or cdlOFNLongNames
' Set filters.
CommonDialog1.Filter = "All Files (*.*)|*.*|Text" & _
"Files (*.txt)|*.txt|Batch Files (*.bat)|*.bat"
' CommonDialog1.Filter = "AutoForm Files (*.doc) (*.rtf)|*.doc;*.rtf|All " & _
"Files (*.*)|*.*"
' Specify default filter.
CommonDialog1.FilterIndex = 2 ' Default to TEXT
' Display the Open dialog box.
CommonDialog1.ShowOpen
' Call the open file procedure.
' OpenFile (CommonDialog1.FileName)
Debug.Print CommonDialog1.FileName
Exit Sub
ErrHandler:
' User pressed Cancel button.
Exit Sub
End Sub
Private Sub cmdShowColor_Click()
' Set Cancel to True
CommonDialog1.CancelError = True
On Error GoTo ErrHandler
' Set the Flags property
CommonDialog1.Flags = cdlCFEffects Or cdlCFBoth
' Display the Font dialog box
CommonDialog1.ShowColor
rtb.BackColor = CommonDialog1.Color
Exit Sub
ErrHandler:
' User pressed the Cancel button
Exit Sub
End Sub
Private Sub cmdShowFont_Click()
' Set Cancel to True
CommonDialog1.CancelError = True
On Error GoTo ErrHandler
' Set the Flags property
CommonDialog1.Flags = cdlCFEffects Or cdlCFBoth ' cdlCFPrinterFonts
' Display the Font dialog box
CommonDialog1.ShowFont
If rtb.SelLength = 0 Then
rtb.SelStart = 0
rtb.SelLength = Len(rtb.SelRTF)
End If
rtb.SelFontName = CommonDialog1.FontName
rtb.SelFontSize = CommonDialog1.FontSize
rtb.SelBold = CommonDialog1.FontBold
rtb.SelItalic = CommonDialog1.FontItalic
rtb.SelUnderline = CommonDialog1.FontUnderline
rtb.SelStrikeThru = CommonDialog1.FontStrikethru
rtb.SelColor = CommonDialog1.Color
Exit Sub
ErrHandler:
' User pressed the Cancel button
Exit Sub
End Sub
Private Sub cmdSaveFile_Click()
Dim strFileName As String
Dim ans As Integer
CommonDialog1.Flags = &H2 ' Overwrite Flag
CommonDialog1.Filter = "RTF|*.rtf|Text|*.txt"
CommonDialog1.ShowSave
On Error GoTo SaveProblems
strFileName = CommonDialog1.FileName
If CommonDialog1.FilterIndex = 1 Then
CommonDialog1.DefaultExt = "rtf"
rtb.SaveFile strFileName
Else
CommonDialog1.DefaultExt = "txt"
rtb.SaveFile strFileName, rtfText
End If
Exit Sub
SaveProblems:
MsgBox "Can’t save the file, try again.", vbCritical
Exit Sub
End Sub
Private Sub Form_Load()
Label1.Caption = "Open File into RTB " & vbCrLf & _
"Save File from RTB" & vbCrLf & _
"Show Font" & vbCrLf & _
"Change selected text" & vbCrLf & _
" or all text." & vbCrLf & _
"Show Color" & vbCrLf & _
"Change BackColor of RTB"
End Sub
Sub SaveMultipleFiles()
Dim strOrigDir As String
Dim strNewDir As String
Dim varTemp As Variant
Dim lngIdx As Long
strNewDir = "D:\Temp\"
With CommonDialog1
.Flags = cdlOFNAllowMultiselect Or cdlOFNLongNames Or cdlOFNExplorer
.ShowSave
varTemp = Split(.FileName, vbNullChar)
End With
If IsArray(varTemp) Then
If UBound(varTemp) = 0 Then
FileCopy varTemp(lngIdx), strNewDir & Right$(varTemp(lngIdx), Len(varTemp(lngIdx)) - InStrRev(varTemp(lngIdx), "\"))
Else
strOrigDir = varTemp(0)
For lngIdx = LBound(varTemp) + 1 To UBound(varTemp)
FileCopy strOrigDir & "\" & varTemp(lngIdx), strNewDir & varTemp(lngIdx)
Next
End If
End If
End Sub
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.