I am working on a solution which uses PDFSharp to print greetings on A4 paper.
When the paste button is clicked the Messagebox shows the verse with the added VBCrLf in it, so the paste code is OK, but the it runs the 'txbVerse_TextChanged' which I think it is where it hangs.
Here is the code for the form:
Can anyone see why it hangs?Code:Imports System.Data.SqlClient Imports System.Drawing Imports PdfSharp Imports PdfSharp.Drawing Imports PdfSharp.Pdf Imports PdfSharp.Drawing.Layout Enum pageOrientation Landscape Portrait End Enum Enum pagesize A4 A5 End Enum Public Class PrintFrm Private Const Lf As String = vbCrLf Private connectionString As String = "Data Source=DESKTOP-S7FRNAL\SQLEXPRESS;Initial Catalog=Verses_Find;Integrated Security=True" Public Property dt As Object Private Sub PrintFrm_Load(sender As Object, e As EventArgs) Handles MyBase.Load Dim Print As New PrintFrm Me.TopMost = True Me.WindowState = FormWindowState.Maximized 'TODO: This line of code loads data into the 'Verses_FindDataSet4.TxtColor' table. You can move, or remove it, as needed. Me.TxtColorTableAdapter.Fill(Me.Verses_FindDataSet4.TxtColor) 'TODO: This line of code loads data into the 'Verses_FindDataSet3.CSize' table. You can move, or remove it, as needed. Me.CSizeTableAdapter.Fill(Me.Verses_FindDataSet3.CSize) For Each oFont As FontFamily In FontFamily.Families cboFont.Items.Add(oFont.Name) Next End Sub Private Sub btnPasteVerse_Click(sender As Object, e As EventArgs) Handles btnPasteVerse.Click ' Determine if there is any text in the Clipboard to paste into the text box. If Clipboard.GetDataObject().GetDataPresent(DataFormats.Text) = True Then ' Determine if any text is selected in the text box. If txbVerse.SelectionLength > 0 Then ' Ask user if they want to paste over currently selected text. If MessageBox.Show("Do you want to paste over current selection?", "Cut Example", MessageBoxButtons.YesNo) = DialogResult.No Then ' Move selection to the point after the current selection and paste. txbVerse.SelectionStart = txbVerse.SelectionStart + txbVerse.SelectionLength End If End If ' Paste current text in Clipboard into text box. txbVerse.Paste() End If End Sub Private Sub txbVerse_TextChanged(sender As Object, e As EventArgs) Handles txbVerse.TextChanged Dim FSize As Single FSize = 24 txbVerse.Font = New Font(cboFont.Text, FSize, FontStyle.Regular) MessageBox.Show(Replace(txbVerse.Text, Chr(13) & Chr(10), " VBCrLf ")) Dim cboVal1 As String Dim lstVal2 As Integer Dim cboVal3 As String Dim boxX As Integer Dim boxY As Integer Dim cellw As Integer Dim cellh As Integer Dim sql As String = Nothing Dim sqlAdaptor As SqlDataAdapter Dim dt As New DataTable Dim CID As Integer Dim ort As String Dim Narrative As String Narrative = Nothing ort = Nothing Using connection As New SqlConnection(connectionString) connection.Open() Dim selectStatement = $"Select CID, BoxX, BoxY, Cellw, Cellh, Size, ort, Narrative From CSize Where CID = {cboCSize}" sqlAdaptor = New SqlDataAdapter(selectStatement, connection) dt = New DataTable() sqlAdaptor.Fill(dt) MessageBox.Show(Narrative, "Card Size") End Using Dim document As PdfDocument ' Create a new PDF document document = New PdfDocument() document.Info.Title = "Created with PDFsharp" ' Create an empty page Dim page As PdfPage = document.AddPage If ort = "L" Then page.Orientation = CType(pageOrientation.Landscape, PdfSharp.PageOrientation) page.Width = XUnit.FromMillimeter(297) page.Height = XUnit.FromMillimeter(210) Else page.Orientation = CType(pageOrientation.Portrait, PdfSharp.PageOrientation) page.Width = XUnit.FromMillimeter(210) page.Height = XUnit.FromMillimeter(297) End If ' Draw the text Dim Ftext As String = txbVerse.Text Dim Font As String = Nothing cboVal1 = CStr(cboFont.SelectedValue) lstVal2 = CInt(lstFSize.SelectedValue) cboVal3 = CStr(cboColor.SelectedValue) Dim gfx As XGraphics gfx = XGraphics.FromPdfPage(page) Dim Cfont As XFont = New XFont("French Script MT", 20, XFontStyle.Regular) Dim tf As XTextFormatter tf = New XTextFormatter(gfx) Dim FColor As String = cboVal3 Dim rect As XRect rect = New XRect(boxX, boxY, cellw, cellh) gfx.DrawRectangle(XBrushes.SeaShell, rect) tf.Alignment = XParagraphAlignment.Center tf.DrawString(Ftext, Cfont, XBrushes.Blue, rect, XStringFormats.TopLeft) ' Save the document Dim filename As String = "verse.pdf" document.Save(filename) ' ...and start a viewer. Process.Start(filename) End Sub Private Sub btnClose3_Click(sender As Object, e As EventArgs) Handles btnClose3.Click Close() End Sub End Class




Reply With Quote
