Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 103,582 times

Contents

Related Categories

Common Dialog Control - Using the Colour Dialog

Using the Colour Dialog

You can use the set colour dialog to allow the user to select a system color. Below are the most common parameters you will need to set before displaying the Open Dialog Box.

Parameter Changes...
DialogTitle the Title displayed in the Dialog Box
Color the selected color
Flags custom settings such as disable custom color button.
CancelError whether an error occurs when the dialog box is cancelled.

The following code displays a colour dialog. When the user clicks OK, it sets the forms background colour to the one selected.

' Sets the Dialog Title to Save File
CommonDialog1.DialogTitle = "Select Colour"

CommonDialog1.CancelError = True
' Set flags - enabled the Custom Color button
CommonDialog1.Flags = cdlCCFullOpen
' Enables error handling to catch cancel error
On Error Resume Next
' display the set colour dialog box
CommonDialog1.ShowColor

If Err Then
    ' This code runs if the dialog was cancelled
    Msgbox "Dialog Cancelled"
    Exit Sub
End If
' Sets Form1 background color to the selected colour
Form1.Backcolor = CommonDialog1.Color

James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.

Comments

  • Re: Common Dialog Control

    Posted by ffrreeaakk on 20 Feb 2007

    I know what you're thinking about. I have exactly the same problem. I don't know how to make Common Dialog Box show such window: http://Common Dialog Control

    Posted by al_sebie on 26 Jul 2006

    Dear Sir


    Thanks for you help and I like you way that you got it, but my questation is Can I use Common Dialog without use File Type? because I need only open folder without select file "Onl...

  • Posted by takedownca on 20 Apr 2004

    Using the FileName (path) and FileTitle (filename) properties of the dialog control,
    [code]
    Dim FilePathOnly As String

    FilePathOnly = Left(FileName, Len(FileName) - Len(FileTitle))
    'or
    FilePath...

  • Posted by darkwolf on 24 Dec 2003

    [code]OpenPath = App.Path & "\templates\"

    OpenFileWName = TreeView1.SelectedItem

    If OpenFileWName = OpenPath Then
    MsgBox "You can not select a directory. Please select a template file."
    E...

  • path

    Posted by darkwolf on 20 Dec 2003

    is there a way of getting just the path of the file this way, without the file name in it?
    E.G. if i open
    C:\Windows\Wini.ini
    can i get the program to read just
    C:\Windows
    from that?