I want to open a pdf file when clicking the button.
I have this code so far, using the FileOpenDialogBox:
private void button1_Click(object sender, EventArgs e)
{
openFD.InitialDirectory = "C:";
openFD.Title = "Open dogov";
openFD.FileName = "";
openFD.Filter = "PDF Files(*.pdf)|*.pdf";
openFD.ShowDialog();
Chosen_file = openFD.FileName;
openFD.FilterIndex=1;
openFD.FileName=Chosen_file;
try
{
if (openFD.ShowDialog() == DialogResult.OK)
{
textBox15.Text = this.openFD.FileName;
}
}
finally
{
}
}
and I fill the textbox with the file path.Now I would like to open the pdf file when clicking on the textbox which contains the path, but I don't know how.
Can anybody help me please?
I would appreciate any help a lot.
VulpesPosted Feb 9, 2012, 4:24 AM
NelPosted Feb 9, 2012, 8:55 AM
FroglegPosted Feb 9, 2012, 4:26 AM
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;// for file system
using System.Diagnostics;// to run a process
namespace Pdffy
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "PDF Files (*.pdf)|*.pdf";
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
textBox1.Text = openFileDialog1.FileName;
Process.Start(openFileDialog1.FileName);
}
}
}
}