|
-
Aug 23rd, 2005, 04:48 PM
#1
Re: Image & Text On A Standard Command Button (Not Graphical Style!)- XP/2K/98
Yes, I have that issue too. I think the only way to get rid of it is to subclass the button and do it a more proper way. But this way is very simple for most programmers.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 23rd, 2005, 06:19 PM
#2
Re: Image & Text On A Standard Command Button (Not Graphical Style!)- XP/2K/98
why dont you lockwindowupdate it so it cant dissapear?
-
May 6th, 2012, 07:39 AM
#3
New Member
Re: Image & Text On A Standard Command Button (Not Graphical Style!)- XP/2K/98
 Originally Posted by lintz
RobDog888, this is exactly what I was looking for however I noticed that if you click on the command button and then move your mouse off the button (while still holding down left mouse button) the image disappears.
 Originally Posted by RobDog888
Yes, I have that issue too. I think the only way to get rid of it is to subclass the button and do it a more proper way. But this way is very simple for most programmers. 
Hello Folks,
I am sorry for reviving this very old thread. But since there are many people that still use the good ol' VB6, I think it's worth that I should tell everybody how to solve the issue above.
The "disappearing picture" issue is not encountered when using XP Visual Styles (with the manifest file).
But the workaround should be applied anyway, because when the application is executed under Windows Vista or W7, the will be no Visual Styles even with the manifest file (actually, there is a hack for this, but I haven't tried it yet).
This issue can be solved in two ways.
The simpler way is this (no code modification is need): set the "DragMode" property of the "Command1" control to "1 - Automatic".
But as a side efect, this will show a rectangle when you click the button and drag the mouse while the left mouse button is still pressed.
The less simple way is described below.
It relies on the following workaround: whe set the focus to another control (we can even use the picture as a dummy control), then we set the focus back to the Command1 button).
However, as (yet another) side effect, the picture won't update its offeset properly because some events are disturbed this way (especially the MouseUp event), but I resolved this by saving the picture box absolute position in two variables and modified the code as needed (I tried to bold each modificatin):
Code:
Option Explicit
'<10/21/2004 ROBDOG888 VB/OUTLOOK GURU>
Private mlX As Long
Private mlY As Long
' these two variables will keep the position of the picture after the execution of "MakeGraphicalOutOfStandardButton" sub
Private pictop As Long
Private picleft As Long
Private Sub Command1_Click()
Picture1.Move picleft, pictop
Picture1.Refresh
MsgBox "Look Manavo11, a standard command button with an aligned image and text in it!", vbOKOnly + vbInformation, _
"RobDog888's Picture Button Demo" '
End Sub
Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Picture1.Move picleft + mlX, pictop + mlY
Picture1.Refresh
End Sub
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If X < 0 Or Y < 0 Or X > Command1.Width Or Y > Command1.Height Then
Picture1.Enabled = True ' if using Picture1 as a dummy control, we'll make sure it is enabled, otherwise the SetFocus method will trigger an error
Picture1.SetFocus
Command1.SetFocus
Picture1.Enabled = False ' disable the Picture1
Picture1.Move picleft, pictop
Picture1.Refresh
End If
End Sub
Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Picture1.Move picleft, pictop
Picture1.Refresh
End Sub
Private Sub Form_Load()
Select Case GetFullVersion
Case "2.5.1", "2.5.2" 'XP, SERVER 2003, +
'OFF - NO OFFSET WHEN CLICKED - oh no, wait... let's create an effect, though
mlX = 1 * Screen.TwipsPerPixelX
mlY = 1 * Screen.TwipsPerPixelY
Case Else Case Else
'ON - OFFSET WHEN CLICKED
mlX = 15
mlY = 15
End Select
'CHANGE THE LAST PARAMETER TO CHANGE THE ALIGNMENT
MakeGraphicalOutOfStandardButton Command1, Picture1, BS_LEFT
' Saving picture position
picleft = Picture1.Left
pictop = Picture1.Top
'ALIGN THE TEXT OPPOSITE OF THE PICTURE ALIGNMENT
AlignButtonText Command1, BS_RIGHT
End Sub
As a "bonus", I modified the code to create a "pressed" effect for XP and 2K3.
Please note that I assumed that the "Enabled" property of the Picture1 control is set to false.
I hope this may be useful to someone some day.
Yes, I know there are custom controls that mimic XP visual style. But those controls are immune to any other style/theme made for XP. Moreover, applications using those custom controls won't display Vista/W7 styles (providing the hack in the link above will work).
Last edited by silkworm; May 7th, 2012 at 02:00 AM.
Reason: a few typos
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|