Click here to Skip to main content
15,120,268 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I've hit a snag with a Windows Forms application I'm building. The users want a control on a form into which they can paste formatted text and images. I've used a RichTextBox but the quality of image after pasting in is poor and very degraded compared to the original. It also doesn't allow for the image to be resized.

Is there any way I can correct these defects or am I simply taking the wrong approach? Is there an alternative I should have considered?

Thanks,

Tony.
Posted
Updated 26-Jul-13 2:07am
v2

1 solution

Hi Tony,

Here's the code for inserting images into RichTextBox, this will allow the user to resize the image but the image quality gets quite bad when resized (except when it's in the print preview dialogue).

VB
Public Sub InsertPicture()
        Try
            Dim GetPicture As New OpenFileDialog
            GetPicture.Filter = "PNGs (*.png), Bitmaps (*.bmp), GIFs (*.gif), JPEGs (*.jpg)|*.bmp;*.gif;*.jpg;*.png|PNGs (*.png)|*.png|Bitmaps (*.bmp)|*.bmp|GIFs (*.gif)|*.gif|JPEGs (*.jpg)|*.jpg"
            GetPicture.FilterIndex = 1
            GetPicture.InitialDirectory = "C:\"
            If GetPicture.ShowDialog = Windows.Forms.DialogResult.OK Then
                Dim SelectedPicture As String = GetPicture.FileName
                Dim Picture As Bitmap = New Bitmap(SelectedPicture)
                Dim cboard As Object = Clipboard.GetData(System.Windows.Forms.DataFormats.Text)
                Clipboard.SetImage(Picture)
                Dim PictureFormat As DataFormats.Format = DataFormats.GetFormat(DataFormats.Bitmap)
                If RichTextBoxPrintCtrl1.CanPaste(PictureFormat) Then
                    RichTextBoxPrintCtrl1.Paste(PictureFormat)
                End If
                Clipboard.Clear()
                Clipboard.SetText(cboard)
            End If
        Catch ex As Exception
        End Try
    End Sub
    Private Sub Button_Click()
        InsertPicture()
    End Sub


If this code isn't what you need or if it's the same code you're using now then here's an alternative option here.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900