回复 9楼 op123
程序代码:
#pragma once
namespace DrawNumberString {
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>
/// Form1 摘要
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: 在此处添加构造函数代码
//
}
protected:
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::PictureBox^ pictureBox1;
private: System::Windows::Forms::Button^ button1;
protected:
private:
/// <summary>
/// 必需的设计器变量。
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
void InitializeComponent(void)
{
this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
this->button1 = (gcnew System::Windows::Forms::Button());
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox1))->BeginInit();
this->SuspendLayout();
//
// pictureBox1
//
this->pictureBox1->BackColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>(static_cast<System::Byte>(255)), static_cast<System::Int32>(static_cast<System::Byte>(224)),
static_cast<System::Int32>(static_cast<System::Byte>(192)));
this->pictureBox1->Location = System::Drawing::Point(0, 0);
this->pictureBox1->Name = L"pictureBox1";
this->pictureBox1->Size = System::Drawing::Size(200, 200);
this->pictureBox1->TabIndex = 0;
this->pictureBox1->TabStop = false;
//
// button1
//
this->button1->BackColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>(static_cast<System::Byte>(255)), static_cast<System::Int32>(static_cast<System::Byte>(128)),
static_cast<System::Int32>(static_cast<System::Byte>(0)));
this->button1->Font = (gcnew System::Drawing::Font(L"宋体", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(134)));
this->button1->ForeColor = System::Drawing::Color::Blue;
this->button1->Location = System::Drawing::Point(48, 203);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(104, 39);
this->button1->TabIndex = 1;
this->button1->Text = L"D R A W";
this->button1->UseVisualStyleBackColor = false;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(200, 246);
this->Controls->Add(this->button1);
this->Controls->Add(this->pictureBox1);
this->Name = L"Form1";
this->Text = L"Form1";
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox1))->EndInit();
this->ResumeLayout(false);
}
#pragma endregion
private: Void draw_num_str(Point^ inpoint, int wide, int num)
{
Image^ drawimg = gcnew Bitmap(wide, wide);
Graphics^ g = Graphics::FromImage(drawimg);
SolidBrush^ MyBrush = gcnew SolidBrush(Color::Cyan);
g->FillRectangle(MyBrush, Rectangle(inpoint->X + wide / 20, inpoint->Y + wide / 20, (wide * 9) / 10, (wide * 9) / 10));
MyBrush->Color = Color::Black;
g->FillEllipse(MyBrush, Rectangle(inpoint->X + wide / 10, inpoint->Y + wide / 10, (wide * 4) / 5, (wide * 4) / 5));
MyBrush->Color = Color::Cyan;
/*-----------------------------------------------
此处是 DrawString 绘制数字,字符串的地方
6个 DrawString 函数,应该使用哪一个。
实现,如图效果,代码应该如何写。。。。
------------------------------------------------*/
this->pictureBox1->Image = drawimg;
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
draw_num_str(Point(0, 0), 200, 9999);
}
};
}