Results 1 to 12 of 12

Thread: [RESOLVED] code without pressing keys

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    131

    Resolved [RESOLVED] code without pressing keys

    how can i write a code for this

    select all
    ctrl+right shift

    in a richtextbox

    is it possible?


  2. #2
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: code without pressing keys

    VB Code:
    1. Private Sub RichTextBox1_KeyDown(KeyCode As Integer, Shift As Integer)
    2.     ShiftTest = Shift And 7
    3.     If ShiftTest = 3 Then
    4.         RichTextBox1.SelStart = 0
    5.         RichTextBox1.SelLength = Len(RichTextBox1.Text)
    6.         RichTextBox1.SetFocus
    7.     End If
    8. End Sub
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: code without pressing keys

    Quote Originally Posted by ganeshmoorthy
    VB Code:
    1. Private Sub RichTextBox1_KeyDown(KeyCode As Integer, Shift As Integer)
    2.     ShiftTest = Shift And 7
    3.     If ShiftTest = 3 Then
    4.         RichTextBox1.SelStart = 0
    5.         RichTextBox1.SelLength = Len(RichTextBox1.Text)
    6.         RichTextBox1.SetFocus
    7.     End If
    8. End Sub
    What is "ShiftTest"?

  4. #4
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: code without pressing keys

    Im sorry, dint include the declaration part, here is the full code
    VB Code:
    1. Private Sub RichTextBox1_KeyDown(KeyCode As Integer, Shift As Integer)
    2.     Dim ShiftTest As Integer
    3.     ShiftTest = Shift And 7
    4.     If ShiftTest = 3 Then
    5.         RichTextBox1.SelStart = 0
    6.         RichTextBox1.SelLength = Len(RichTextBox1.Text)
    7.         RichTextBox1.SetFocus
    8.     End If
    9. End Sub
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    131

    Re: code without pressing keys


    this code can applyed for mouse down and i need it in form load
    also i need it to be active without pressing any key in keyboard or mouse

    how?

  6. #6
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: code without pressing keys

    Quote Originally Posted by om-yousif
    this code can applyed for mouse down
    Yes, It can be applied to your Keyboard or Mouse Down events.
    Quote Originally Posted by om-yousif
    i need it to be active without pressing any key in keyboard or mouse
    ??????????
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  7. #7
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Jar, Norway
    Posts
    372

    Re: code without pressing keys

    Or:
    VB Code:
    1. Private Sub RichTextBox1_GotFocus()
    2.   SendKeys "^+a"
    3. End Sub
    But why every second time GotFocus the text turn to UPPERCASE?

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    131

    Re: code without pressing keys

    OK ganeshmoorthy
    let me tell you what i need
    i have a richtextbox includes an Arabic Text
    this text will be loaded in Form_Load()

    what i need is to change the Alignment of the richtext to right automatically
    without pressing anything in keyboard or mouse

    these two steps in pressing the keyboard will do this
    select all
    ctrl+right shift

    but i need to convert it to a code in VB so the text's alignment will be changed just when form loaded

  9. #9
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: code without pressing keys

    You can use the keybd_event() API function. Are you sure pressing CTRL+Right Shift aligns the text to the right? It's not working for me.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Const VK_SHIFT = &H10
    4. Private Const VK_CONTROL = &H11
    5. Private Const VK_RSHIFT = &HA1
    6. Private Const VK_A As Integer = 65
    7.  
    8. Private Const KEYEVENTF_EXTENDEDKEY = &H1
    9. Private Const KEYEVENTF_KEYUP = &H2
    10.  
    11. Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, _
    12.     ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
    13.  
    14. Private intActivate As Integer
    15.  
    16. Private Sub Form_Activate()
    17.    
    18.     If intActivate = 0 Then
    19.         'Press down control key.
    20.         keybd_event VK_CONTROL, 0, 0, 0
    21.         'Press right shift.
    22.         keybd_event VK_RSHIFT, 0, 0, 0
    23.         'Release right shift key.
    24.         keybd_event VK_RSHIFT, 0, KEYEVENTF_KEYUP, 0
    25.         'Release control key.
    26.         keybd_event VK_CONTROL, 0, KEYEVENTF_KEYUP, 0
    27.        
    28.         intActivate = 1
    29.     End If
    30.    
    31. End Sub
    32.  
    33. Private Sub Form_Load()
    34.     rtb.SelText = "fjdslkfkj" & vbNewLine & "jflksdfjslkjfd" & vbNewLine & "fjlsdfj"
    35.    
    36.     'select all
    37.     'ctrl+right shift
    38.     With rtb
    39.         .SelStart = 0
    40.         .SelLength = Len(.Text)
    41.     End With
    42.    
    43. End Sub

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    131

    Re: code without pressing keys

    yes DigiRev
    (Ctrl+right shift) will do it

  11. #11
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: code without pressing keys

    Quote Originally Posted by om-yousif
    ...but i need to convert it to a code in VB so the text's alignment will be changed just when form loaded...
    VB Code:
    1. Private Sub Form_Load()
    2.     With RichTextBox1
    3.         .SelStart = 0
    4.         .SelLength = Len (.Text)
    5.         .SelAlignment = 1
    6.     End With
    7. End Sub
    ??

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    131

    Re: code without pressing keys

    thanks for all
    and special thanks for gavio

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width