tagCANDY CGI VBレスキュー(花ちゃん)の Visual Basic 6.0用 掲示板
VBレスキュー(花ちゃん)の Visual Basic 6.0用 掲示板
[ツリー表示へ]  [ワード検索]  [Home]

タイトル RichTextBox からイメージを印刷する方法
投稿日: 2008/06/13(Fri) 14:44
投稿者ちゃちゃまる
画像イメージの転写サンプルをMSからそのまま複写して作成しましたが、
(MS RichTextBox からイメージを印刷する方法)

command2とcommand3がうまく動きません。何が悪いのでしょうか?

command1を押下すると選択した画像を表示する
command2を押下するとpicture1に表示されたイメージをpicture2に複写する
command3を押下するとpicture2を印刷する
-----------------------------------------------------------------------------------
1. Visual Basic で標準EXE プロジェクトを作成します。 Form1 は、既定で作成されます。  
2. PictureBoxes を 2 と 3 つの Form1 の CommandButton コントロールを配置します。
Picture1 と同じぐらい少なくとも大きいように Picture2 のサイズを調整します。  
3. プロジェクト メニューのコンポーネントを選択し、 Microsoft Rich Textbox コントロール6.0 を確認します。  
4. Picture1 の内の RichTextBox コントロールを配置します。  
5. Form1 の 全般 Declarations Section に次のコードを追加します。    

  Option Explicit

      Private Declare Function SendMessage Lib "user32" Alias _
         "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
         ByVal wParam As Long, ByVal lParam As Long) As Long

      Private Const WM_PAINT = &HF
      Private Const WM_PRINT = &H317
      Private Const PRF_CLIENT = &H4&    ' Draw the window's client area
      Private Const PRF_CHILDREN = &H10& ' Draw all visible child
      Private Const PRF_OWNED = &H20&    ' Draw all owned windows

      Private Sub Command1_Click()
      ' Use the .bmp of your choice and make sure to give the full path.
         RichTextBox1.OLEObjects.Add , , "c:\windows\triangles.bmp"
      End Sub

      Private Sub Command2_Click()
         Dim rv As Long
         Picture1.SetFocus  ' So that the button doesn't look pressed
         Picture2.AutoRedraw = True
         rv = SendMessage(Picture1.hwnd, WM_PAINT, Picture2.hDC, 0)
         rv = SendMessage(Picture1.hwnd, WM_PRINT, Picture2.hDC, _
              PRF_CHILDREN + PRF_CLIENT + PRF_OWNED)
         Picture2.Picture = Picture2.Image
         Picture2.AutoRedraw = False
         Command1.SetFocus  ' Return Focus
      End Sub

      Private Sub Command3_Click()
         Printer.PaintPicture Picture2.Picture, 0, 0
         Printer.EndDoc
      End Sub



- 関連一覧ツリー をクリックするとツリー全体を一括表示します)

古いスレッドにレスはつけられません。