投稿時間:2007/03/28(Wed) 16:03 投稿者名:Road
Eメール:
URL :
タイトル:Re^2: テキストの背景色の変更方法について
お返事ありがとうございます。 以下のようなプログラムで、無事に動作させることができました。
関数の宣言等:
Public Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" ( _ ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Type CHARFORMAT2 cbSize As Integer wPad1 As Integer dwMask As Long dwEffects As Long yHeight As Long yOffset As Long crTextColor As Long bCharSet As Byte bPitchAndFamily As Byte szFaceName As String * 32 wPad2 As Integer wWeight As Integer sSpacing As Integer crBackColor As Long lcid As Long dwReserved As Long sStyle As Integer wKerning As Integer bUnderlineType As Byte bAnimation As Byte bRevAuthor As Byte bReserved1 As Byte End Type
Public Const EM_GETCHARFORMAT = &H43A Public Const EM_SETCHARFORMAT = &H444 Public Const SCF_SELECTION = &H1 Public Const CFM_BACKCOLOR = &H4000000
マウスでテキストを選択した時、選択範囲のテキストの背景色を赤色にするプログラム:
Private Sub RichTextBox1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim cf2 As CHARFORMAT2 cf2.cbSize = Len(cf2) SendMessage RichTextBox1.hWnd, EM_GETCHARFORMAT, SCF_SELECTION, cf2 cf2.dwMask = CFM_BACKCOLOR cf2.dwEffects = 0 cf2.crBackColor = RGB(255, 0, 0) SendMessage RichTextBox1.hWnd, EM_SETCHARFORMAT, SCF_SELECTION, cf2
End Sub
|