Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

So easy I'm almost embarressed to ask

Posted on 2001-07-23
12
Medium Priority
?
174 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 100 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses

877 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