Solved

So easy I'm almost embarressed to ask

Posted on 2001-07-23
12
162 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
Comment Utility
>what property I need to use
.Value = True
0
 
LVL 15

Expert Comment

by:ameba
Comment Utility
' 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
Comment Utility
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
 
LVL 15

Expert Comment

by:ameba
Comment Utility
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
Comment Utility
Or, use checkboxes, style=graphical
0
 
LVL 14

Expert Comment

by:wsh2
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:DwarfBaby
Comment Utility
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
Comment Utility
Thanks, wsh2  ;-)
Or use optionbuttons (style=graphical)
To select one option, use:
    Option1(2).Value = True
0
 
LVL 15

Expert Comment

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

Author Comment

by:DwarfBaby
Comment Utility
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
Comment Utility
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
Comment Utility
and use code:
    Me.Toolbar1.Buttons(1).Value = tbrPressed
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now