Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

An Uncommon Solution to a Common Compact Framework Problem  : Page 5

Use these flexible UncommonDialog dialog classes to lift the restrictions built into the CommonDialog classes delivered with the .NET Compact Framework.


advertisement
The MP3PropertiesDialog
Observant readers will notice that there is actually a sixth method in the MP3Browser code file, called OnPropertiesButton, which takes the MP3Browser class a step further overriding the properties button to display a subclass of the PropertiesDialog.

Inspecting the PropertiesDialog code, you'll find that all its visual controls are contained within Panels in exactly the same fashion as the FileSystemBrowser. So I merely created a new Form in Visual Studio, put two tabs on it and placed some fields for the ID3 tag information on the first tab. After building the layout, I closed the designer, opened the code view and changed the inherited class to the PropertiesDialog (this functionally becomes an irreversible step since Visual Studio does not support visual inheritance for Compact Framework forms).

As you can see from the code listing there were only two methods I needed to override to achieve my goal, InitializeDialog and ProcessPropertyObject.

protected override void InitializeDialog() { base.InitializeDialog(); foreach(string panelkey in this.Panels.Keys) { System.Windows.Forms.Panel panel = this.Panels[panelkey]; this.tabPageFileInfo.Controls.Add(panel); } this.textBoxSongTitle.Enabled = false; this.textBoxArtist.Enabled = false; this.textBoxAlbum.Enabled = false; this.numericUpDownTrackNo.Enabled = false; }

Leveraging the Panels collection provided by the superclass, I just moved all the panels containing the controls used to display the FileSystemInfo properties to the second tab. This is done in the InitializeDialog method; nothing very intricate or special about the effort, just the easy benefits of a little planning.

protected override void ProcessPropertyObject() { base.ProcessPropertyObject(); Mueller.Utils.ID3.ID3Tag tags = null; tags = Mueller.Utils.ID3.ID3Reader.GetFileInfo( (System.IO.FileInfo)this.PropertyObject); if(tags != null) { this.textBoxSongTitle.Text = tags.SongTitle; this.textBoxArtist.Text = tags.Artist; this.textBoxAlbum.Text = tags.Album; this.numericUpDownTrackNo.Value = int.Parse(tags.Track); } }

 
Figure 5. MP3PropertiesDialog: The dialog lets you inspect the ID3 tags and file properties of an MP3 music file.
The PropertiesDialog does its real work in the ProcessPropertyObject method. This method gets called just before the form is displayed. The class uses the object passed during construction, retrievable through the classes PropertyObject property (which is either the DirectoryInfo or FileInfo object obtained from the currently selected TaggedListViewItem at the time the user clicks the Properties button), to populate the form fields. To preserve that behavior, it calls the superclass's ProcessPropertyObject method immediately and then reads the ID3 tags from what is assumed to be a FileInfo object. Figure 5 shows the PropertiesDialog.

This high-speed tour through the still emerging UncommonDialog API demonstrates not only a drop-in replacement for some of the CommonDialog subclasses but also an extensible system meant to keep pace with the needs of more configurable systems. The MP3Browser demonstration project shows the kind of flexibility that you can easily extend to browser subclasses for viewing FTP or WebDAV servers, or—with a little more effort—adapted to work with LDAP hierarchies.



Guy Rish is a ColdFusion and .NET developer at Vente as well as President at Gestaltech. He is an active developer and author using various languages and technologies. He has contributed work in books on ColdFusion MX, Flash MX, and Dreamweaver MX.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date