Solved

So easy I'm almost embarressed to ask

Posted on 2001-07-23
12
164 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
  • 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA open file from excel cell 4 42
Adding to a VBA? 6 69
Added a column screws up code 5 57
How to read File Date Created using VB6 8 38
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

806 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