dcsimg
Results 1 to 3 of 3

Thread: FilePreview - without printing.

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2018
    Posts
    5

    FilePreview - without printing.

    Hi everyone...

    I have a Windows Forms Application... There is a Listview wich contains the files of a folder...

    I want to get a Preview of the File, when i change a selection. No printing, just a small preview from 1st page...

    Is that possible with PrintPreviewControl? I'm not able to fill it on my Form.

    Name:  New.jpg
Views: 71
Size:  19.6 KB

    I tried this:

    Code:
        Private Sub FolderView_SelectedIndexChanged(sender As Object, e As EventArgs) Handles FolderView.SelectedIndexChanged
    
            Me.PrintPreviewControl2.Document.DocumentName = LabelOrdner.Text & "\" & (FolderView.FocusedItem.Text)   ' Like C:\Test\Files\Testdok1.docx
            Me.PrintPreviewControl2.UseAntiAlias = True
    
        End Sub
    Error is:
    Code:
    System.NullReferenceException
      HResult=0x80004003
      Nachricht = Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
      Quelle = Testprojekt
      Stapelüberwachung:
       bei Testprojekt.Startseite.FolderView_SelectedIndexChanged(Object sender, EventArgs e) in C:\Users\schuette\Desktop\RAApp\RAApp\RAApp\Startseite.vb: Zeile101
       bei System.Windows.Forms.ListView.OnSelectedIndexChanged(EventArgs e)
       bei System.Windows.Forms.ListView.WmReflectNotify(Message& m)
       bei System.Windows.Forms.ListView.WndProc(Message& m)
       bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       bei System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       bei System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       bei System.Windows.Forms.Control.SendMessage(Int32 msg, IntPtr wparam, IntPtr lparam)
       bei System.Windows.Forms.Control.ReflectMessageInternal(IntPtr hWnd, Message& m)
       bei System.Windows.Forms.Control.WmNotify(Message& m)
       bei System.Windows.Forms.Control.WndProc(Message& m)
       bei System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       bei System.Windows.Forms.Form.WndProc(Message& m)
       bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       bei System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       bei System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       bei System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
       bei System.Windows.Forms.Control.DefWndProc(Message& m)
       bei System.Windows.Forms.Control.WndProc(Message& m)
       bei System.Windows.Forms.ListView.WndProc(Message& m)
       bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       bei System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       bei System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       bei System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       bei System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       bei System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
       bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
       bei Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       bei Testprojekt.My.MyApplication.Main(String[] Args) in : Zeile81
    Any Ideas?

    Thank you....
    Attached Images Attached Images  

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    99,760

    Re: FilePreview - without printing.

    Printing in Windows Forms is done using a PrintDocument and GDI+. You need to draw everything to be printed with code. The same code is used to generate a preview and to print on paper. Unless you want to draw whatever is contained in your files, using a PrintPreviewControl is not the way to go.

    In order to display the contents of a file, either you need to understand the file format and be able to read the contents and display it, or you must use a component that does. You could use a WebBrowser control to display PDF and Office files, assuming that you can already view those files in IE. That would require Office to be installed for the Office files and a PDF reader to be installed that includes an ActiveX control. I think that IE should display text files without issue too, or you could just use a TextBox. For other file types, you'd need to do a bit more work and displaying them in your app may not be possible.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2018
    Posts
    5

    Re: FilePreview - without printing.

    Thanks for your reply. Sad, i thought its much more easier

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width