2016-08-03 62 views
0
Private Sub btnPrint_Click(sender As Object, e As EventArgs) Handles btnPrint.Click 
     CaptureScreen() 
     'used to created file path 
     Dim orderNum As String = Val(txtNum.Text) 'gets value of Invoice/PO number 
     Dim orderType As String = GroupBox3.Text 'gets value of either its a Invoice or PO` 

     'saves printscreen to PictureBox 
     PictureBox1.Image = bmpBackground 
     'saves printscreen to file path 
     PictureBox1.Image.Save("\\PCLIQFS\Shared_Data\PCLiq Scale-Shots\" + orderType + " " + orderNum + ".jpg", Imaging.ImageFormat.Jpeg) 

     'creates variable of filePath 
     Dim filePath As String = "\\PCLIQFS\Shared_Data\PCLiq Scale-Shots\" + orderType + " " + orderNum + ".jpg" 
     'checks to see if file is already in filePath 
     If File.Exists(filePath) Then 
      Dim folderPath = Path.GetDirectoryName(filePath) 
      Dim fileName = Path.GetFileNameWithoutExtension(filePath) 
      Dim extension = Path.GetExtension(filePath) 
      Dim fileNumber = 0 

      Do 
       'increments file name 
       fileNumber += 1 
       filePath = Path.Combine(folderPath, 
             String.Format("{0} ({1}){2}", 
                 fileName, 
                 fileNumber, 
                 extension)) 
      Loop While File.Exists(filePath) 
     End If 
     'saves new image 
     PictureBox1.Image.Save(filePath) 
    End Sub 

我想在用戶單擊打印按鈕時保存圖像,但由於圖像已經存在,因此它會一次創建兩個圖像。如果再次單擊打印按鈕,我只想創建另一個圖像。如何使它成爲只有在再次單擊打印按鈕時才運行代碼才能運行文件名的增量?單擊按鈕時創建多個圖像文件

回答

1

評論以下行;

PictureBox1.Image.Save("\\PCLIQFS\Shared_Data\PCLiq Scale-Shots\" + orderType + " " + orderNum + ".jpg", Imaging.ImageFormat.Jpeg) 

因爲您將圖像保存在代碼的末尾。

+0

謝謝。那工作 –