PDA

Просмотр полной версии : RichTextBox


MaximusRS
18.09.2011, 23:27
Добрый вечер!! Кто знает как добавить картинку в RichTextBox в C#? помогите пожалуйста.

Hellost
18.09.2011, 23:40
private void button1_Click(object sender, System.EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.DefaultExt = "*.*";
openFileDialog1.Filter = "All Files|*.*";

if(openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK &&
openFileDialog1.FileName.Length > 0)
{
// Open an bitmap from file and copy it to the clipboard.
Bitmap myBitmap = new Bitmap (openFileDialog1.FileName);
// Copy the bitmap to the clipboard.
Clipboard.SetDataObject(myBitmap);

// Get the format for the object type.
DataFormats.Format myFormat = DataFormats.GetFormat(DataFormats.Bitmap);

// After verifying that the data can be pasted, paste it.
if(richTextBox1.CanPaste(myFormat))
{
richTextBox1.Paste(myFormat);
return;
}
else
{
MessageBox.Show("The data format that you attempted to paste is not supported by this control.");
return;
}
}
}

MaximusRS
19.09.2011, 00:11
Hellost спасибо за код, а как допустим вставить содержание вордовского документа...

•theSaboteur•
19.09.2011, 15:04
richTextBox1.LoadFile(filePath, RichTextBoxStreamType.PlainText);