School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,131 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,057 people online right now. Registration is fast and FREE... Join Now!




Getting started with Open, save, print, font dialog boxes

 
Reply to this topicStart new topic

> Getting started with Open, save, print, font dialog boxes, Using MS common dialog control

Nikhil_07n
Group Icon



post 31 Jan, 2009 - 01:21 AM
Post #1


Intro:

The common dialog, contrary to some people’s beliefs, doesn’t actually do anything itself. It just is a easy to use pointer for other objects. The following dialogs can be show: ShowOpen, ShowSave, ShowColor, ShowFont, ShowPrinter, and ShowHelp.

The first step in the common dialog control is to include it in your project. To do this, go to Project > Components > Microsoft Common Dialog Control 6.0 (SP 3).

After this, you will see a little box in your control toolbox. Click this and drag it onto your form. The default name is CommonDialog1.

2) Types

(i) Show Open

The ShowOpen dialog lists of files and folders on your computer.

Screen:
IPB Image
By nikhil_07n at 2009-01-31
Example:

CODE

With CommonDialog1 'use this because we will have a lot of code with the box
     .DialogTitle = "Open"  'this sets the caption for the title bar on the dialog
     .InitDir = "D:\"  'this sets the initial director for the dialog box
     .Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
     'the filter property is what specifies which file types to display.  The
     '(*.txt) is not necessary.
     'as you can see, the file name comes first then the *.type comes
     'next after the |. This is important

     .ShowOpen  'this event actually displays the open dialog box
End With
RichText1.LoadFile CommonDialog1.FileName

'NOTE :Rich text box is used!



(ii)ShowSave
The ShowSave dialog, as well as the ShowOpen, lists the files and folders of your computer. You can make new folders with this dialog.

Screen:
IPB Image
By nikhil_07n at 2009-01-31
Example:

CODE

With CommonDialog1  'open a with statement as there is a lot of code
     .DialogTitle = "Save As"  'sets the dialog title
     .InitDir = "D:\"  'sets the initial directory
     .Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"  'sets the file
     'types

     .ShowSave  'show the dialog
End With

RichText1.SaveFile CommonDialog1.FileName  'save to the specified file

(iii)ShowColor
The Color dialog box allows a user to select a color from the specified color palette, or they can even make their own custom color.


Screen:
[IMG]http://img207.imageshack.us/img207/894/colornb3.jpg[/IMG]
By [URL=http://profile.imageshack.us/user/nikhil_07n]nikhil_07n[/URL] at 2009-01-31

Example:
[code]
With CommonDialog1  'open a with block
          .DialogTitle = "Color"  'set the title
          .ShowColor  'show the dialog
     End With
    
     Form1.BackColor = CommonDialog1.Color  'set the backcolor to the
     'color selected


(iv)ShowFont
The Font Dialog box is the one with the most properties, but it is the most useful if you are making a text editor. (Or another app where the user needs to set the font.)

Example:
CODE

With CommonDialog1  'open the with dialog
     .DialogTitle = "Font"   'set the dialog title
     .Flags = cdlCFBoth Or cdlCFEffects   'set the flags so you can
     'access the fonts* and the strikethru, underline, color

     .ShowFont  'show the dialog
End With

Richtext1.SelFontName = CommonDialog1.FontName  'set the selected font’s name
Richtext1.SelFontSize = CommonDialog1.FontSize  'set the selected font’s size
Richtext1.SelBold = CommonDialog1.FontBold  'set the selected font’s bold property
Richtext1.SelItalic = CommonDialog1.FontItalic  'set the selected font’s italic property
Richtext1.SelStrikeThru = CommonDialog1.FontStrikethru  'set the selected font’s strikethrough property
Richtext1.SelUnderline = CommonDialog1.FontUnderline  'set the selected font’s underline property


To get more help , download the attachment, its a notepad created by me when i was beginner.

NOTE: It DOES NOT use ShowFont, ShowColor Options of Common DialoG box. I've created my own Font Selection.


Attached File(s)
Attached File  Notepad.zip ( 10.55k ) Number of downloads: 262
Go to the top of the page
+Quote Post


Register to Make This Ad Go Away!


Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 


Lo-Fi Version Time is now: 11/21/09 02:39PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month