Draw Image on RichTextBox



#pragma once

namespace My47 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
///
/// Summary for Form1
///
/// WARNING: If you change the name of this class, you will need to change the
/// 'Resource File Name' property for the managed resource compiler tool
/// associated with all .resx files this class depends on. Otherwise,
/// the designers will not be able to interact properly with localized
/// resources associated with this form.
///

public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
///
/// Clean up any resources being used.
///

~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::RichTextBox^ Rtf;
private: System::Windows::Forms::Button^ BtnDrawImage;
protected:
private:
///
/// Required designer variable.
///

System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

void InitializeComponent(void)
{
this->Rtf = (gcnew System::Windows::Forms::RichTextBox());
this->BtnDrawImage = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// Rtf
//
this->Rtf->Location = System::Drawing::Point(12, 11);
this->Rtf->Name = L"Rtf";
this->Rtf->Size = System::Drawing::Size(268, 190);
this->Rtf->TabIndex = 0;
this->Rtf->Text = L"";
//
// BtnDrawImage
//
this->BtnDrawImage->Location = System::Drawing::Point(12, 216);
this->BtnDrawImage->Name = L"BtnDrawImage";
this->BtnDrawImage->Size = System::Drawing::Size(267, 35);
this->BtnDrawImage->TabIndex = 1;
this->BtnDrawImage->Text = L"Draw Image";
this->BtnDrawImage->UseVisualStyleBackColor = true;
this->BtnDrawImage->Click += gcnew System::EventHandler(this, &Form1::BtnDrawImage_Click);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(292, 266);
this->Controls->Add(this->BtnDrawImage);
this->Controls->Add(this->Rtf);
this->Name = L"Form1";
this->Text = L"Form1";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
this->ResumeLayout(false);
}
#pragma endregion
//Draw Image on RichTextBox
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
Rtf->BackColor=Color::Red;
this->Text="DrawImage on RichTextBox";
this->FormBorderStyle=Windows::Forms::FormBorderStyle::FixedToolWindow;
this->BackColor=Color::Gray;
}
private: System::Void BtnDrawImage_Click(System::Object^ sender, System::EventArgs^ e) {
Graphics^g;
Bitmap^b;
b=gcnew Bitmap("C:\\Flower.Bmp");
g=Rtf->CreateGraphics();
g->DrawImage(b,Rectangle(10,10,200,200));
}
};
}