Click here to Skip to main content
11,703,632 members (64,463 online)
Click here to Skip to main content

OLE container surrogate for .NET

, 13 Mar 2013 CPOL 22.6K 2.4K 17
Rate this:
Please Sign up or sign in to vote.
COM OLE-container analog for .NET

Introduction  

Microsoft Visual Basic versions 6.0 and 5.0 provide an OLE container control for embedding OLE objects directly on forms. The OLE container control provides a means for embedding OLE objects such as Microsoft Excel workbooks, Microsoft PowerPoint presentations, and Microsoft Word documents. But Visual Studio .NET does not provide an OLE container control for Windows Forms: http://support.microsoft.com/kb/304562/. Microsoft recommends achieving a similar functionality by using the Microsoft WebBrowser control to host the document if the document uses ActiveX. Excel, PowerPoint, and Word all support ActiveX. Therefore, documents from those sources may be displayed by using the WebBrowser control.

But the WebBrowser control doesn't embed Office documents because of security problems.

The PreviewContainer control solves this problem.  

Possibilities:    

  • preview MS Office documents (Excel, Word, PowerPoint and etc) 
  • preview and zooming different image formats like .jpg, .bmp and etc
  • preview and browsing multi-paged .tif files 
  • preview file formats which WebBrowser control support like .htm, .xml, and etc.
  • developers can extend PreviewContainer control for support different file formats 

Screenshots  

Excel document preview:

Multipages TIFF preview:

Background

Solution is based on preview handlers mechanism:

Using the code

Using of this control is very simple: 

  1. Add a reference to PreviewsHandlers.dll
  2. Drop the PreviewContainer on a Windows Form 
  3. Call the CreateLink method of the control with the full file path:
  4. this.previewContainer.CreateLink(@"c:\test.tif");
  5. If you want to browse multi-paged content (like multi-page tif), you can use these methods:
  6. ((IPaginalPreviewHandlerHost)this.previewContainer).PreviousPage();
    	((IPaginalPreviewHandlerHost)this.previewContainer).NextPage(); 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Alexei Bouravtsev
Software Developer (Senior) GNIVC
Russian Federation Russian Federation
I'm a Russian (Moscow Aviational Institute 1996-2002) Software Engineer living in Moscow, Russia. I have a long experience in Windows programming and have been developing large GUI, Real Time Enterprise Client/Server C# applications and SQL Server/Oracle databases.

My point of interests is high load enterprise applications.

You may also be interested in...

Comments and Discussions

 
QuestionIs It possible preview by print layout? Pin
Member 448700712-Apr-15 18:56
memberMember 448700712-Apr-15 18:56 
Questionvisual basic .net Pin
rjmendoza28-Jan-15 14:49
memberrjmendoza28-Jan-15 14:49 
AnswerRe: visual basic .net Pin
Alexei Bouravtsev3-Feb-15 0:23
memberAlexei Bouravtsev3-Feb-15 0:23 
Questionedit Pin
Jayson Ragasa22-Nov-14 5:11
memberJayson Ragasa22-Nov-14 5:11 
AnswerRe: edit Pin
Alexei Bouravtsev3-Feb-15 0:22
memberAlexei Bouravtsev3-Feb-15 0:22 
QuestionAppears to have issues with more than one Preview Container on a WinForm Pin
gr8yt200028-Jul-14 5:35
membergr8yt200028-Jul-14 5:35 
QuestionRe: Appears to have issues with more than one Preview Container on a WinForm Pin
TourInfernale26-Feb-15 0:42
memberTourInfernale26-Feb-15 0:42 
QuestionXLSM? Pin
Member 1084311825-May-14 16:04
memberMember 1084311825-May-14 16:04 
AnswerRe: XLSM? Pin
Alexei Bouravtsev3-Feb-15 0:25
memberAlexei Bouravtsev3-Feb-15 0:25 
QuestionGreat Pin
User_Beginner18-Mar-14 8:14
memberUser_Beginner18-Mar-14 8:14 
QuestionCategory does not exist.? Pin
Member 1018047328-Nov-13 5:14
memberMember 1018047328-Nov-13 5:14 
AnswerRe: Category does not exist.? Pin
Alexei Bouravtsev25-Mar-14 22:34
memberAlexei Bouravtsev25-Mar-14 22:34 
QuestionOpen PPT Pin
conqu1212-Sep-13 19:05
memberconqu1212-Sep-13 19:05 
QuestionTry compilation with SharpDevelop 4.3.2 Pin
moebius221-Aug-13 5:55
membermoebius221-Aug-13 5:55 
AnswerRe: Try compilation with SharpDevelop 4.3.2 Pin
Alexei Bouravtsev25-Mar-14 22:42
memberAlexei Bouravtsev25-Mar-14 22:42 
QuestionError "Excel has stopped working" Pin
Jason Orphanidis13-Aug-13 0:24
memberJason Orphanidis13-Aug-13 0:24 
AnswerRe: Error "Excel has stopped working" Pin
Alexei Bouravtsev13-Aug-13 1:50
memberAlexei Bouravtsev13-Aug-13 1:50 
GeneralMy vote of 5 Pin
Katja240323-Jul-13 22:51
memberKatja240323-Jul-13 22:51 
QuestionProvided project not running Pin
rexpertq10-Jun-13 4:18
memberrexpertq10-Jun-13 4:18 
AnswerRe: Provided project not running Pin
Alexei Bouravtsev13-Jun-13 3:54
memberAlexei Bouravtsev13-Jun-13 3:54 
GeneralRe: Provided project not running Pin
rexpertq13-Jun-13 18:56
memberrexpertq13-Jun-13 18:56 
GeneralRe: Provided project not running Pin
Alexei Bouravtsev13-Jun-13 20:38
memberAlexei Bouravtsev13-Jun-13 20:38 
QuestionWord and Excel documents problem. Pin
Isildure11-Mar-13 4:51
memberIsildure11-Mar-13 4:51 
AnswerRe: Word and Excel documents problem. Pin
Alexei Bouravtsev13-Mar-13 5:27
memberAlexei Bouravtsev13-Mar-13 5:27 
QuestionDownloads ? Pin
Member 324609830-Nov-12 7:40
memberMember 324609830-Nov-12 7:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150819.1 | Last Updated 13 Mar 2013
Article Copyright 2012 by Alexei Bouravtsev
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid