-
[RESOLVED] How to make a button "Visibly Pressed" when I click a Picture
I have standard command button with a Picture Object on top of it.
When I click the button, the button is "PRESSED".
What I want is when I click on the Picture on top of the button, the button is not "PRESSED" and I want it to be visibly "PRESSED", even though I didnt trigger the command's click event.
Is that possible??
-
Re: How to make a button "Visibly Pressed" when I click a Picture
instead of putting a picture on top of the button, you can set the buttons graphical property to true. this way u can put a picture on the button itself.
-
Re: How to make a button "Visibly Pressed" when I click a Picture
The reason i use picture is that I wanted to align the pic to left and text to right.
-
Re: How to make a button "Visibly Pressed" when I click a Picture
In the click event of the picture box, execute whatever code you need to execute then setfocus to the command button. It should look the same way it looks when it gets pressed.
Although, for the life of me, I can't figure out why you are bothering to use a command button in the first place if that isn't what is going to be executing any code.
-
Re: How to make a button "Visibly Pressed" when I click a Picture
Well, it helps but not really what I expected, I mean not 100% exact as it was "PRESSED".
-
Re: How to make a button "Visibly Pressed" when I click a Picture
:wave: Its because of my CodeBank thread on aligning a picture and text on a standard button.
http://www.vbforums.com/showthread.php?t=323449
-
Re: How to make a button "Visibly Pressed" when I click a Picture
You can also use a Checkbox set to Graphical, which appears to be a command button, but has a state for ON and OFF.
-
Re: How to make a button "Visibly Pressed" when I click a Picture
Yes, but then you wont get the XP themes applied to it.
-
Re: How to make a button "Visibly Pressed" when I click a Picture
Yes, I used the code to align the Pic. And I am using check box and set to graphical.
So, how to make the button "PRESSED" when clicked on the PIC??
Can you guide me? I need this badly.
Thanks
-
Re: How to make a button "Visibly Pressed" when I click a Picture
I use them in an app, and it changes the foreground color when it is ON.
Makes it obviou that the state has changed.
-
Re: How to make a button "Visibly Pressed" when I click a Picture
What is STATE ON and OFF?
-
Re: How to make a button "Visibly Pressed" when I click a Picture
With a checkbox in graphical state your button will, once clicked, be pressed down but till not popup until you click it again.
-
Re: How to make a button "Visibly Pressed" when I click a Picture
Sorry about that. State ON is vbchecked.
Put a checkbox on your form, and set its style to graphical.
See this example.
VB Code:
Option Explicit
Private Sub Check1_Click()
If Check1.Value = vbChecked Then
Check1.BackColor = vbRed
Else
Check1.BackColor = vbBlue
End If
End Sub
The button will be grey when you start the app, unless you change the color beforehand, or in the properties.
-
Re: How to make a button "Visibly Pressed" when I click a Picture
So, is there anyway to make the button PRESSED when I click the picture objects?
-
Re: How to make a button "Visibly Pressed" when I click a Picture
I reasearched and tested a few things and it may be possible but its going to require subclassing of the button and allot of code. Nothing I would really like to try tonight (tired) to be honest. But in case you want to try this is what to look for.
The BM_SETSTATE message sets the push state of a button and the WM_PAINT message does the painting of the new style.
-
Re: How to make a button "Visibly Pressed" when I click a Picture
Ok Thanks for your help so far..
I will try it out my self.
-
Re: How to make a button "Visibly Pressed" when I click a Picture
Did you try the option button with the picture on it? It has two states as I've said before. You could even change the picture for each state just as I've changed the backcolor.
-
Re: How to make a button "Visibly Pressed" when I click a Picture
I think it's a better way to create a custom control for your need. Creating custom control you need to implement the functionality of the button state liKe "PRESSED" for Mousedown event and "UNPRESSED" for mouseup event. Give it a public touch.
-
Re: How to make a button "Visibly Pressed" when I click a Picture
The Graphical Checkbox would work fine.
-
Re: How to make a button "Visibly Pressed" when I click a Picture
Dglienna, your missing the point. He doesnt want to use the checkbox in graphical style as it doesnt support XP theming or custome positioning of the image.
I completely forgot that wokawidget wrote a custom button in his component suite download that has a project called XP Button. It allows you to draw custom shaped buttons with images too.
http://www.vbforums.com/showthread.php?t=328044
-
Re: How to make a button "Visibly Pressed" when I click a Picture
In some way , I love check Box set a graphical, which it allows me to change the font color, but when click, the value is true, which does not satisfied me, i need to uncheck that.
Somehow, Standard button will not allow to change the font color, but at least is a BUTTON.
How to use BM_SETSTATE?
Is it something to do with API??
-
Re: How to make a button "Visibly Pressed" when I click a Picture
Yes, it is and its involves a process called subclassing which is a process of intercepting the windows message stream going to the window and acting or reacting to certain messages as they are called and overridding their original actions. Too much code to whip up a quick example. :(
-
Re: How to make a button "Visibly Pressed" when I click a Picture
How do I declare BM_SETSTATE??
Should I declare it something like this??
Public Const BS_vCENTER As Long = &HC00
And what is &HC00??
-
Re: How to make a button "Visibly Pressed" when I click a Picture
Here's something I did
VB Code:
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any _
) As Long
Private sub Picture1_Click()
Call pushButton(cmdNew,BM_SETSTATE)
End Sub
Public Function pushButton(bttn As CommandButton,style as Long)
Dim ss As Long
ss = SendMessage(bttn.hwnd, style, True, 0)
End Function
But I DO NOT know how to declare BM_SETSTATE