Monday, June 15, 2009

VB Day Nine (9) Microsoft Common Dialog Control

MS Common Dialog control is used to enable your software to browse your system for paths.
it has many methods which are very much useful i.e to save file just call its method showsave or to open a file just call its showopen method and it will give you the small window where you can save and open a file respectively.

lets do it practically.
take a Microsoft Rich TextBox Control 6.0 and rename it as TxtExample
also make its multi line=true
and Scroll Bars= 3-Both

now take the microsoft common dialog control and rename it as CDC.

take two command buttons
rename first as CmdOpen and make its caption =Open
rename second as CmdSave and make its caption =Save

now goto click event of CmdOpen and code as


CDC.Filter = "Text files *.Txt Word Documents *.Doc All Files *.*"
CDC.ShowOpen
TxtExample.LoadFile CDC.FileName


Now goto click event of CmdSave and Code as below

CDC.Filter = "Text files *.Txt Word Documents *.Doc All Files *.*"
CDC.ShowSave
TxtExample.SaveFile CDC.FileName


so thats about how to save and load text files into rich text box

Now we want to show font formatting window (by calling ShowFont method of CDC).
for this purpose first goto Properties of CDC
and make the Flags=1

and Take a Command Button rename it as CmdFont and make its Caption=Font
on click event of CmdFont do the following code


CDC.ShowFont
TxtExample.SelBold = CDC.FontBold
TxtExample.SelItalic = CDC.FontItalic
TxtExample.SelUnderline = CDC.FontUnderline
TxtExample.SelFontName = CDC.FontName
TxtExample.SelFontSize = CDC.FontSize
TxtExample.SelStrikeThru = CDC.FontStrikethru



Now take another Command Button and rename it as CmdFontColor and make its caption=FontColor
goto click event of this button and paste the following code

CDC.ShowColor

TxtExample.SelColor = CDC.Color

and thats it. i think this will be enough for you people right now and if need more help the let me know about.

1 comment:

  1. what are the most common usages of common dialog control?

    ReplyDelete