opening the Windows Print Pictures dialog using VB.Net - vb.net

I want to call the Windows Print Pictures dialog using VB.net. the one Windows comes up with when you go to print a picture, the one that lets you print full page, 8X10, 4X6, 5X7, contact sheet, etc.
I've tried using printdocument and printdialog but those only give you the standard print dialog window for documents.
I've searched Google and all the results were completely unrelated to the Print Pictures dialog and therefore completely useless.
I've seen the same question for C+ here
Print image using windows print image dialog
using CLSID_PrintPhotosDropTarget COM object.
but this doesn't really help me since I'm using VB.net (Visual Studio 2008 to be precise) but I'm including it here as it has a screenshot of the dialog I am trying to call.
any help would be appreciated.

Okay, just this once, I will translate for you but you need to find an on line converter that you like. Many examples are available in C#. Also please take the tour to learn how to ask a proper question.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'The C# code
'String fileName = #"C:\Development\myImage.tif";//pass in Or whatever you need
'var p = New Process();
'p.StartInfo.FileName = fileName;
'p.StartInfo.Verb = "Print";
'p.Start();
Dim fileName = "C:\Users\xxxx\Desktop\Graphics\Baby owl.jpg"
Dim p = New Process
p.StartInfo.FileName = fileName
p.StartInfo.Verb = "Print"
p.Start()
End Sub

Related

Visual Studio 2017 Visual Basic - How to pass variable from one event to another

I'm learning VS VB, so please forgive the ignorance.
I have built a form that accepts a file search pattern, searches for matching files and then displays the file names (up to 10) in text boxes.
If you double click on the file name (up to 10) text box, I want it to call a routine to open Powerpoint and display the first slide.
I've searched around and can't find any information thats helpful to me for 2017.
At this point, my code looks like below (just shows that I have the full file name).
Public Sub DisplaySong(ByVal SongFileName)
Dim SongToDisplay As String = ""
Dim i As Integer
' get the full song path/name
Try
Dim strFiles As String() = Directory.GetFiles(strSearchPath.ToString, SongFileName.ToString, IO.SearchOption.AllDirectories)
i = 0
' should never be more than 1 song
For Each SongFileName In strFiles
SongToDisplay = strFiles(i)
i = i + 1
Next
Catch ex As Exception
MessageBox.Show("Error processing Display Song: Finding Song!! ")
End Try
MessageBox.Show("Song Selected: " + SongToDisplay.ToString)
End Sub
The examples I've talk about adding the COMs, but I don't see "Microsoft Graph Object Library" in the 2017 version. I selected MS PowerPoint and the MS Graph 14.0, thinking (hoping) that's what I needed.
When I add
Dim oApp as PowerPoint.Application
into the subroutine, I get the error message that it's not defined. I know how to do this in Access VB 2010, but I don't know how to do this in VS VB 2017.
Any help is appreciated.
Dummy me. Adding
Imports Microsoft.Office.Interop
Fixed the problem.

directly print when using code in VB.NET

I use the following code
Dim PrintR_ As Printing.PrinterSettings = ReportViewer1.PrinterSettings
PrintR_.PrinterName = "Microsoft XPS Document Writer"
ReportViewer1.PrintDialog(PrintR_)
However, when executed, the following form appears
All I want is not to see this screen and to print directly based on the printer's specific name
Thanks for everyone who helps.

How to read VB formatted code from a text file?

I writing a pair of programs in visual basics that will consist of a client and receiver. The client is completed making an output text file similar to below.
Dim FileName As String = "Text.txt"
Dim message As String
Dim file As System.IO.StreamWriter
'lblmessage.text says "Call MsgBox("Hello!", 0, "Version Beta 0.3")"
lblmessage.text = message
Dim Drive As String = "C:\hello world\" & FileName
file = My.Computer.FileSystem.OpenTextFileWriter(Drive, True)
file.WriteLine(message)
file.Close()
A sister program that is designed to be a reader will read the generated file.
The program will then take the text located in the selected file and use it as code in the readers programming.
Best example I can show...
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim fileReader As String
fileReader = My.Computer.FileSystem.ReadAllText("C:\hello world\Text.txt")
fileReader
End Sub
where "fileReader" is suppose to run the generated code from the previous program and use it as code it the Reader.
The point of this program is to create help tickets in the client and have a tool for reviewing these ticket in the same way they were submitted through the second app.
vba and vb.net is different. I'm not sure in which language your doing your stuff.
vba: use the ScriptControl.Eval command to execute a bunch of commands.
vb.net: it's a bit more code. you can use VBCodeProvider Class. s this SO Question: Load VB.net code from .txt file and execute it on fly using System.CodeDom.Compiler
UPDATE
I found a perfekt resource if you are interested in how to do it right and how it works in the background: http://www.codemag.com/article/0211081

Vb.Net preview report from access database

I am using visual studio 2010 to develop my desktop application and ms access database. I have already designed reports in access database and they are working perfectly. Now my concern is that is it possible to use these access reports in my Vb.Net application?
I need this because it would be much easier to distribute the software instead of using crystal report where I will need to install a run time machine for crystal reports.
It's possible to do but it's a horrible implementation. You basically have to launch Access, open the database file in Access, then navigate down and launch the report. There is no way to just "view" the report inside your app. It will only show inside Access.
I think your best option is to use ReportViewer control if you don't want to use Crystal Reports.
I found this: https://support.microsoft.com/kb/317113?wa=wsignin1.0
To preview or to print an Access report, you call the OpenReport method of the DoCmd object. When you call OpenReport, one of the arguments that you pass determines whether the report is previewed on the screen, or whether it is sent to the printer:
' Preview a report named Sales:
oAccess.DoCmd.OpenReport(ReportName:="Sales", View:=Access.AcView.acViewPreview)
' Print a report named Sales:
oAccess.DoCmd.OpenReport(ReportName:="Sales", View:=Access.AcView.acViewNormal)
But I haven't been able to find much info/help regarding OpenReport method or DoCmd object.
I am not a proffesional developer, but after long research it's worked for my project.
I would like to open directly from MS Access, my existing reports and then to open these from not default installation folder path (different for each one pc). The third requirement was to open more than one report (Not all together).
Design:
Form8.vb [Design]
vb.Net Code:
Imports System.ComponentModel
Imports Microsoft.Office.Interop.Access
Public Class Form8
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim oAccess As New Microsoft.Office.Interop.Access.Application()
Dim CurDir As String = System.AppDomain.CurrentDomain.BaseDirectory
Dim FPath As String = CurDir & "\YourDatabase.accdb"
oAccess.Visible = True
oAccess.OpenCurrentDatabase(FPath)
If ComboBox1.Text = "Your text" Then
oAccess.DoCmd.OpenReport(ReportName:="Your Report Name", View:=AcView.acViewPreview)
ElseIf ComboBox1.Text = "Your text2" Then
oAccess.DoCmd.OpenReport(ReportName:="Your Report Name", View:=AcView.acViewPreview)
ElseIf ComboBox1.Text = "Your text3" Then
oAccess.DoCmd.OpenReport(ReportName:="Your Report Name", View:=AcView.acViewPreview)
End If
End Sub
End Class
Replace YourDatabase with YourDatabaseName, Replace Your text,Your text1,Your text2,Your text3 with YourText, Replace Your Report Name with the Name of your report Name, As needed.
Finally, in order for this solution to work, you need:
1) Your (Conn.open) connection to look like this:
Dim dbsource As String = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source = |DataDirectory|\Your DB.accdb"
2) In Solution Explorer, Your database to include in your project or to your setup project, to be installed with your project. like this:
Solution Explorer [image]
SetUp Project link
3) At server explorer, Data Connection the (Sourse) Database file name, must be with the full path name e.g like this:
C:\Users\User\Desktop\YourDatabase.accdb, and the connection String at the Properties like this:
Provider=Microsoft.ACE.OLEDB.12.0;Data Source = "C:\Users\User\Desktop\YourDatabase.accdb".
I hope this helps!!!
The following code:
Preview a report named Sales:
oAccess.DoCmd.OpenReport(ReportName:="Sales", View:=Access.AcView.acViewPreview)
Print a report named Sales:
oAccess.DoCmd.OpenReport(ReportName:="Sales", View:=Access.AcView.acViewNormal)
But I haven't been able to find much info/help regarding OpenReport method or DoCmd object.
This will only work if you are using VB.Net to automate the Access application. This will open the Access application and allow you to view or print the reports just as if you were running Access directly. However, you need to have the Access application (not just the .mdb or .accdb file) on the computer that is running the VB.Net application.
I have not found any way to utilize the Access reports without having Access on the computers running the VB.Net application. I'm looking into using Crystal Reports for the application I'm working on now.

Print Dialog Does not show up in Crystal Report Viewer on 64 bit machine

I have a client, who is running Windows 2008 Server 64 bit. He is running our software, it has a built in crystal report viewer functionality.
The print dialogue just wouldn't work no matter what. It worked on our 32 bit box and we verified it. I verified it on our 64 bit box, and the print dialogue didn't open either. I did some research online. And one suggestion is to set m_printDlg.UseEXDialog = True. I tried that, but that DID NOT WORK EITHER...
I am kind of frustrated now. Has anyone encountered the similar issue? If so, please let me know.
Here is the code snippet.
#Region " Methods "
Public Overrides Sub PrintReport()
' NOTE: Do not use bug in reportviewer
'MyBase.PrintReport()
Dim objRpt As ReportDocument = CType(Me.ReportSource, ReportDocument)
If m_printDlg Is Nothing Then
m_printDlg = New PrintDialog
End If
m_printDlg.PrinterSettings = ReportEngine.GetPrinterSettings(objRpt)
m_printDlg.UseEXDialog = True
'm_printDlg.ShowDialog(Me)
If m_printDlg.ShowDialog = DialogResult.OK Then
ReportEngine.PrintReportDocument(objRpt, m_printDlg.PrinterSettings)
End If
End Sub
End Region
Try compiling your application to target any or target x64 (if already any) and see if that has any effect.