How to render extended unicode character in PrintPreviewDialog - vb.net

I want to display 🡸 (a WIDE-HEADED LEFTWARDS HEAVY BARB ARROW Symbol) in a PrintDocument. It does not render correctly; it only shows a box. Using Windows Forms with vb.net 4.6; Visual Studio 2017.
I know I have the correct character and font because it displays in a button just fine on the form. Yet in the PrintPreviewDialog it won't render correctly. What do I need to do?
Public WithEvents Doc As New PrintDocument
Public Sub ShowDialog()
'page settings
Me.Doc.DefaultPageSettings = ... set letter size, default printer, margins
Me.Doc.PrinterSettings = ...default printer
Me.Doc.DefaultPageSettings.PaperSize.RawKind = PaperKind.Letter
'show dialog
Dim dlgPreview As New PrintPreviewDialog
dlgPreview.Document = Me.Doc
dlgPreview.WindowState = FormWindowState.Maximized
dlgPreview.ShowDialog()
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs) Handles Doc.PrintPage
Dim arrow As String = Char.ConvertFromUtf32(&H1F87A)
Dim f As New System.Drawing.Font("Microsoft Sans Serif", 11, FontStyle.Regular)
e.Graphics.DrawString(arrow, f, Brushes.Black, 100, 100)
End Sub

By looping through all my installed fonts I was able to find a font that displays the correct character. In my case it was "Segoe UI Symbol".

Related

vb.net change location of 2 different texts in button

I have a problem with another line of text in button. This code works fine but not how i want.
Another line of text displays on top of the button and i want to it display on bottom of the button.
Code:
Private Sub btnCheckPass_Paint(sender As Object, e As PaintEventArgs) Handles btnCheckPass.Paint
Dim btn = DirectCast(sender, Button)
Dim text = ("Skontrolujte silu vašich hesiel a ich prelomovosť")
Dim smallFont As New Font(btn.Font.FontFamily, btn.Font.Size - 10)
e.Graphics.DrawString(text.ToString(),
btn.Font,
Brushes.Gray,
New Rectangle(New Point(), btn.Size),
New StringFormat With {.Alignment = StringAlignment.Center})
End Sub
Does anyone know how to solve this?
Thanks

User Change Font of Selected Text in RichTextBox

This should be easy, however it is eluding me. I have a RichTextBox in VB.NET that the user enters text in. I want them to be able to select some text, then change the font properties of the selection.
Here is something I have quickly written up for you.It will get ALL of the installed fonts on the system and add them to a combobox, so you wont have to add them all manually.Also I have made it so whenever you change the font type for a combobox that I have added, It will update the RichTextBox's font.
Imports System.Drawing.Text
Public Class Form1
''CREATE ANOTHER COMBOBOX TO CHANGE THE SIZE OF THE TEXT USING THE SAME METHOD
''AS THE FONT COMBOBOX.
Dim FONTSIZE = 8
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim InstalledFonts = New InstalledFontCollection
Dim FontFamilies() As FontFamily = InstalledFonts.Families
For Each Font As FontFamily In FontFamilies
ComboBox1.Items.Add(Font.Name)
Next
''THE END USER WONT BE ABOUT TO EDIT THE INSTALLED ITEMS IN THE COMBOBOX
''THE STARTING FONT IS CONSOLAS
ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList
ComboBox1.Text = "Consolas"
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
''THIS WILL CHANGE THE HIGHLIGHTED "SELECTED" TEXT FONT ONLY
''AS ASKED FOR IN QUESTION
RichTextBox1.SelectionFont = New Drawing.Font(ComboBox1.Text, FONTSIZE)
End Sub
End Class
You will need to add a combobox to your form and a richtextbox for this too work.If you have any trouble, let me know and I'll try and help you work.
Thanks Werdna, your answer gave me some direction. I did go with the FontDialog as in the end I wanted to allow other font changes such as style and color.
Private Sub rtf_Notes_MouseUp(sender As Object, e As MouseEventArgs) Handles rtf_Notes.MouseUp
'Test for right-click
If (e.Button = Windows.Forms.MouseButtons.Right) Then
With FontDialog1
.ShowColor = True
If (.ShowDialog() = Windows.Forms.DialogResult.OK) Then
rtf_Notes.SelectionFont = New Drawing.Font(.Font.Name, .Font.Size, .Font.Style)
rtf_Notes.SelectionColor = .Color
End If
End With
End If
End Sub

Why do the WordWrap and AutoSize properties on a Text Box behave differently if the text boxes are added dynamically?

I am creating some textboxes dynamically in a custom control (actually is just a panel with a binding source that adds other sub controls at runtime.
In some of those I am setting WordWrap=True because I am expecting large text. But the textbox has only one line. Also I notice that I have to set the property AutoSize to False. When I add dynamically textboxes in a form everything is working fine (even without setting the AutoSize and the WordWrap.
Dim txt as new textbox
txt.Multiline = True
txt.AutoSize = False
txt.Size = New Size(100, 50)
txt.WordWrap = True
txt.Location = New Point(10, 10)
Me.Controls.Add(txt) 'Me is my custom Control
I checked the property WordWrap for the text box after I inserted them (with double click) and it is True.
Any ideas why I face this strange behaviour in my custom control?
Edit:
The problem is that I cannot make my text to wordwrap. So although I set MultiLine to true, AutoSize to false, WordWrap to True, the text is not changing lines. I don't want to add scrollbars.
You could adjust the .Height of the TextBox when its .Text changes:
Public Class Form1
Dim txt As TextBox
Sub maketb()
txt = New TextBox
txt.Multiline = True
txt.Size = New Size(100, 50)
txt.WordWrap = True
txt.Location = New Point(10, 10)
Me.Controls.Add(txt)
End Sub
Sub SetHeight(sender As Object, e As EventArgs)
Dim target = DirectCast(sender, TextBox)
Dim fn = target.Font
Dim gr = target.CreateGraphics()
Dim lrMarginSize = target.Margin.Left + target.Margin.Right
Dim tbMarginSize = target.Margin.Top + target.Margin.Bottom
Dim h = gr.MeasureString(target.Text, fn, target.Width - lrMarginSize).Height + tbMarginSize
target.Height = CInt(Math.Ceiling(h))
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
maketb()
AddHandler txt.TextChanged, AddressOf SetHeight
txt.Text = "dfgd dfd gg hgljhhkjlh jhkkj hkjh hghjg hgjhgz hfjsdhfytu hgjahg ht gretyt jgagury agha gty ajhg ajgx"
End Sub
End Class
Guys I have to apologize.
The error was in my xml (I had MultiLine instead of Multiline), so my textbox was never Multiline.
Thanks for your time, Sorry for spending it without meaning.

RichTextBox in VB.NET

I want set a line of text link in rich text box of vb.net. Like for example: I want to know you
The word want, I want to set a link word.
Can I do that?
This is how I would do it.
Dim linkLa As New LinkLabel
linkLa.LinkColor = Color.Red
Dim link As LinkLabel.Link = linkLa.Links.Add(0, 13, "http://www.stackoverflow.com")
linkLa.Text = "Stackoverflow"
AddHandler linkLa.LinkClicked, AddressOf Link_Clicked
richTextBox1.Controls.Add(linkLa)
Private Sub Link_Clicked(ByVal sender As Object, ByVal e As EventArgs)
MessageBox.Show("clicked")
End Sub
I have an answer for you. This will allow you to show the link target address as a tooltip. (little pop up bubble.) Other than that, it's similar to Stan R.'s answer.
Put this code under the "add link" button (or whatever you're calling it) in your program
Note: I put comments before each line, so it's easier to follow!
'define the text and link targets
Dim linktext As String = LinkTextbox.Text 'LinkTextbox is just the textbox where the user inputs the text of the link
Dim linktarget As String = LinkTargetTextbox.Text 'LinkTargetTextBox is just the textbox where the user inputs the target URL of the link
'Define the LinkLabel
Dim lnk As New LinkLabel
'if you want, you can set the different properties, like font or linkcolor, programmatically after defining the linklabel, for instance:
lnk.LinkColor = Color.Blue
'set tooltip
lnk.Tooltip = linktarget
'set the link target
Dim lk As LinkLabel.Link = lnk.Links.Add(0, 13, linktarget)
'set the link text
lnk.Text = linktext
'EventHandler
AddHandler lnk.LinkClicked, AddressOf LinkClicked
'Add the control to the richtextbox
RichTextBox1.Controls.Add(lnk)
'This is the Subroutine that the label will run when clicked (Make sure to put your "End Sub" before this, because it's not part of the button's subroutine)
Private Sub LinkClicked(ByVal sender As Object, ByVal e As EventArgs)
'send link to the browser
Process.Start(linktarget)
End Sub

how do i print my form?

I need to print an image of my VB.Net Windows.Form when the user clicks a button. Is there a good method for doing this?
You need to use the PrintForm component. Please see How to: Print a Form by Using the PrintForm Component:
The PrintForm component enables you to
quickly print an image of a form
exactly as it appears on screen
without using a PrintDocument
component. The following procedures
show how to print a form to a printer,
to a print preview window, and to an
Encapsulated PostScript file.
If you want to amend the image the following code will capture the bitmap and send it to the printer (On the Button1 Click)
Imports System.Drawing.Printing
Public Class Form1
Dim WithEvents mPrintDocument As New PrintDocument
Dim mPrintBitMap As Bitmap
Private Sub m_PrintDocument_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles mPrintDocument.PrintPage
' Draw the image centered.
Dim lWidth As Integer = e.MarginBounds.X + (e.MarginBounds.Width - mPrintBitMap.Width) \ 2
Dim lHeight As Integer = e.MarginBounds.Y + (e.MarginBounds.Height - mPrintBitMap.Height) \ 2
e.Graphics.DrawImage(mPrintBitMap, lWidth, lheight)
' There's only one page.
e.HasMorePages = False
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Copy the form's image into a bitmap.
mPrintBitMap = New Bitmap(Me.Width, Me.Width)
Dim lRect As System.Drawing.Rectangle
lRect.Width = Me.Width
lRect.Height = Me.Width
Me.DrawToBitmap(mPrintBitMap, lRect)
' Make a PrintDocument and print.
mPrintDocument = New PrintDocument
mPrintDocument.Print()
End Sub
End Class
If you really want a snapshot of the form, you'll have to simulate a screen capture. Here's a sample that'll help. It's going to be pretty ugly though, so you may want to consider making it a report using a PDF or report builder.