ホーム » .NET » C# のコードを C++.NET で…

2013年10月
 12345
6789101112
13141516171819
20212223242526
2728293031  

カテゴリー

アーカイブ

ブログ統計情報

  • 77,437 アクセス



C# のコードを C++.NET で…

MSDN にあるサンプルを VC++2008 でビルドする.
MSDN 四角形内にテキストを折り返して描画する


新規プロジェクトで「Windows フォーム アプリケーション」.
「新規プロジェクト」-「Windows フォーム アプリケーション」
Paint のハンドラを追加.
Paint ハンドラの追加


private: System::Void Form1_Paint(System::Object^  sender, System::Windows::Forms::PaintEventArgs^  e) {
/*
  string text2 = “Draw text in a rectangle by passing a RectF to the DrawString method.”;
  using (Font font2 = new Font(“Arial”, 12, FontStyle.Bold, GraphicsUnit.Point))
  {
    Rectangle rect2 = new Rectangle(30, 10, 100, 122);
    // Specify the text is wrapped.
    TextFormatFlags flags = TextFormatFlags.WordBreak;
    TextRenderer.DrawText(e.Graphics, text2, font2, rect2, Color.Blue, flags);
    e.Graphics.DrawRectangle(Pens.Black, Rectangle.Round(rect2));
  }
*/

  String^        text2 = “Draw text in a rectangle by passing a RectF to the DrawString method.”;
  Drawing::Font^     font2 = gcnew    Drawing::Font(“Arial”, 12, FontStyle::Bold, GraphicsUnit::Point) ;
  Drawing::Rectangle^    rect2 = gcnew    Drawing::Rectangle(30,10,100,122) ;
  TextFormatFlags        flags = TextFormatFlags::WordBreak ;
  TextRenderer::DrawText(e->Graphics,text2,font2,*rect2,Color::Blue,flags) ;
  e->Graphics->DrawRectangle(Pens::Black,*rect2) ;
}


RECT または CRect にあたるものは,Drawing::Rectangle .
ここで利用している Font は Drawing::Font としないとエラーになる.
  c:\…\drawt_2\Form1.h(87) : error C2061: 構文エラー : 識別子 ‘Font’
DrawText などの Rectangle はハンドルではなく実体.


2013/11/05
C# の文字列の前の ‘@’
リテラル文字列


MFC での文字列の変数に対する += .
  CString str ;
  str += _T(“123”) ;
C++/CLI で System::String は可能であるが,C# の string ではエラーとなるみたい.


2013/11/06
C# で g.Dispose() ;
  C++ では delete g ;
Graphics.Dispose メソッド

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

コメントする

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

%d人のブロガーが「いいね」をつけました。