Solved

So easy I'm almost embarressed to ask

Posted on 2001-07-23
12
166 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBS file using code from 2nd file (txt or vbs) 4 47
MsgBox 4 71
VB6 ListBox Question 4 55
Powerpoint 2013: Change cell reference in excel link 3 121
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

761 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