How to color the words in Rich Text box automatically like VB Editor?
Posted on January 27, 2012
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 'Controls - How to color the words in Rich Text box automatically like VB Editor? Private Sub Command1_Click() Dim OldSelStart As Long RichTextBox1.TextRTF = "Hello World" ' Clear formatting and change text to Hello World OldSelStart = RichTextBox1.SelStart ' Remember old SelStart ' Color the Hello: RichTextBox1.SelStart = InStr(RichTextBox1.Text, "Hello") - 1 RichTextBox1.SelLength = Len("Hello") RichTextBox1.SelColor = vbRed ' Color the World: RichTextBox1.SelStart = InStr(RichTextBox1.Text, "World") - 1 RichTextBox1.SelLength = Len("World") RichTextBox1.SelColor = vbBlue ' Clear selection: RichTextBox1.SelStart = OldSelStart End Sub |
How can i get the mouse to automatically click???? Like on its own.
Posted on January 26, 2012
1 2 3 4 5 6 7 8 9 10 11 | 'System & API - How can i get the mouse to automatically click???? Like on its own. Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, _ ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long) Private Const MOUSEEVENTF_LEFTDOWN = &H2 Private Const MOUSEEVENTF_LEFTUP = &H4 Private Sub Command1_Click() Call mouse_event(MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0) Debug.Print "Am clicking the mouse " & Format$(time, "HH:mm:ss") End Sub |
How to draw a horizontal and vertical line in a picture box?
Posted on January 26, 2012
1 2 3 4 5 6 7 8 9 10 11 | 'Controls - How to draw a horizontal and vertical line in a picture box? 'Insert a picture box and a command button on your form Private Sub Command1_Click() Picture1.ScaleTop = -1 ' Set scale for top of grid. Picture1.ScaleLeft = -1 ' Set scale for left of grid. Picture1.ScaleWidth = 2 ' Set scale (-1 to 1). Picture1.ScaleHeight = 2 Picture1.Line (-1, 0)-(1, 0) ' Draw horizontal line. Picture1.Line (0, -1)-(0, 1) ' Draw vertical line. End Sub |
How to center the Text in a picture box?
Posted on January 25, 2012
1 2 3 4 5 6 7 8 9 | 'Controls - How to center the Text in a picture box? 'Insert a picture box and a command button on your form Private Sub Command1_Click() Const MYTEXT = "I'm centered" Picture1.CurrentX = (Picture1.Width / 2) - (TextWidth(MYTEXT) / 2) Picture1.CurrentY = (Picture1.Height / 2) - (TextHeight(MYTEXT) / 2) Picture1.Print MYTEXT End Sub |
How to count number of characters in RTF except crlf and spaces? (in two ways)
Posted on January 25, 2012
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 'Controls - How to count number of characters in RTF except crlf and spaces? (in two ways) 'Method 1: Private Sub Command1_Click() MsgBox "Total Chars: " & Len(RichTextBox1.Text) & vbCrLf & _ "Chars, No CRLFs: " & Len(Replace(RichTextBox1.Text, vbCrLf, "")) & vbCrLf & _ "Chars, NO CRLFs, No Spaces: " & Len(Replace(Replace(RichTextBox1.Text, vbCrLf, ""), _ " ", "")) End Sub 'Method 2: 'To Calculate the Number of Characters excluding CRLFs (using API): Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _ ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Private Const EM_GETLINECOUNT = &HBA Private Sub Command1_Click() MsgBox "Chars, Excluding CRLF: " & Len(RichTextBox1.Text) - _ (2 * (SendMessage(RichTextBox1.hwnd, EM_GETLINECOUNT, 0, 0) - 1)) End Sub |