Solved

So easy I'm almost embarressed to ask

Posted on 2001-07-23
12
167 Views
Last Modified: 2010-05-02
I have a simple control array of Command buttons(5 to be exact).  I just need to know what property I need to use for the selected Command button to appear pressed.  In Java it's something like KeyDown or Keypress but VB spits that back in my face.   Thanks
0
Comment
Question by:DwarfBaby
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 2
  • 2
12 Comments
 
LVL 15

Expert Comment

by:ameba
ID: 6310467
>what property I need to use
.Value = True
0
 
LVL 15

Expert Comment

by:ameba
ID: 6310487
' Form1, add control array Command1()
Option Explicit

Private Sub Command1_Click(Index As Integer)
    MsgBox Index
End Sub

Private Sub Form_Click()
    If ActiveControl.Name = "Command1" Then
        ActiveControl.Value = True
    End If
End Sub
0
 
LVL 14

Expert Comment

by:wsh2
ID: 6310525
This is MAYBE not as easy as you think.. <sigh>.

One way.. is to define your own graphics (Pressed / Unpressed) and then use them in the Command Button Command1.Picture and Command1.DownPicture property. When you want the Button pressed, just place the pressed graphic in the Picture property.

Another way is to use APIs to modify the command button border metrics. This is obviously much more complicated as the best way to monitor paint events is to incorporate the code into a Pressed / Unpressed Command Button control of its own. Very doable.. but a lot more work <sigh>.

So I suppose.. the real question is.. how much work do you want to do?.. <smile>
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 15

Expert Comment

by:ameba
ID: 6310576
Hi, wsh2

' add control array Command1()
Option Explicit
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal _
    bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" _
    (ByVal wCode As Long, ByVal wMapType As Long) As Long
Private Const VK_SPACE = &H20
Private Const KEYEVENTF_KEYUP = &H2

Private Sub Command1_Click(Index As Integer)
    MsgBox Index
End Sub

Private Sub Form_Click()
    If ActiveControl.Name = "Command1" Then
        'ActiveControl.Value = True   ' too easy
       
        Dim shiftscan%
        shiftscan% = MapVirtualKey(VK_SPACE, 0)
        keybd_event VK_SPACE, shiftscan%, 0, 0
        ' keybd_event VK_SPACE, shiftscan%, KEYEVENTF_KEYUP, 0
    End If
End Sub
0
 
LVL 15

Accepted Solution

by:
ameba earned 25 total points
ID: 6310592
Or, use checkboxes, style=graphical
0
 
LVL 14

Expert Comment

by:wsh2
ID: 6310654
DwarfBaby.. make it easy on yourself.. ameba's suggestion of "use checkboxes, style=graphical" (with a Frame).. is very well placed.. <smile> and a <wink>.
0
 

Author Comment

by:DwarfBaby
ID: 6310688
Wow, I had no Idea this would be so complicated.  This is just a simple database front end for a friend and certainly not worth the trouble.  I think I'll just use toolbar icons or change the color of the text box or something.  Thanks for the ideas anyways.
0
 
LVL 15

Expert Comment

by:ameba
ID: 6310691
Thanks, wsh2  ;-)
Or use optionbuttons (style=graphical)
To select one option, use:
    Option1(2).Value = True
0
 
LVL 15

Expert Comment

by:ameba
ID: 6310697
Thanks.  I'm still not sure what was the question - you don't need any icon...
0
 

Author Comment

by:DwarfBaby
ID: 6310749
I meant toolbar Icon(or toolbar button).  That way I can use the image list control to give the apperance of being compressed.  Certain Items would appear on the form if a certain command button was pressed.  The only reason I was avoiding option buttons was because I am already using several option button arrays on the form and I wanted the main options "Add Item" "Edit Item" and so on to stand out and appear as a seperate form even though I'm just making some objects visable and changing the functions of certain text boxes.    Thanks again for your time.
0
 
LVL 15

Expert Comment

by:ameba
ID: 6310774
Thanks, DwarfBaby.  If you are using Toolbar control, change style of your buttons to 2' tbrButtonGroup or 1' tbrCheck.
0
 
LVL 15

Expert Comment

by:ameba
ID: 6310786
and use code:
    Me.Toolbar1.Buttons(1).Value = tbrPressed
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question