PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Wed Jun 26, 2019 6:51 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Sun Jun 02, 2019 3:19 pm 
Offline

Joined: Fri May 03, 2019 10:10 pm
Posts: 14
I am trying to get the color picked from a combobox into the XBrushes expression so that the user can change the color of the font to the color they wish. think I have sorted out getting the Font name variable into the code, but it does not work for XBrushes.
Due to my little experience of VB I am not sure how to express a variable in the Xbrushes class expression.
The error I get is: 'FColor is not a member of XBrushes'
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



        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 SID As Integer
        Dim ort As String
        Dim Narrative As String
        Narrative = Nothing
        ort = Nothing
        Dim FSize As Integer
        Using connection As New SqlConnection(connectionString)
            connection.Open()
            Dim selectStatement = $"Select SID, 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(cboVal1, lstVal2, XFontStyle.Regular)
        Dim tf As XTextFormatter
        tf = New XTextFormatter(gfx)
       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.FColor, 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 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)
    End Sub

    Private Sub btnClose3_Click(sender As Object, e As EventArgs) Handles btnClose3.Click
        Close()
    End Sub
End Class


Can anyone help please?


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group