|
-
Apr 9th, 2017, 01:17 PM
#1
Re: WithEvents (or something like it)
Any Control that was set to Enabled = False, will "delegate" their Mouse-Messages to the underlying Container.
Knowing that, the solution comes down to writing/defining your own ucLabel.ctl
(which despite having Disabled-State, will render its Text in the normal ForeColor).
The easiest way to do that (if you don't want to fiddle around with your own Text-Renderings) is,
to simply wrap an existing Label-Control within your new ucLabel.ctl.
Here's a small example - the following should go into a new ucLabel.ctl (which hosts a Label, named Label1):
Code:
Option Explicit
'also set the UserControl to CanGetFocus = False in the Property-Grid
Private Sub UserControl_Initialize()
UserControl.Enabled = False
Label1.BackColor = vbRed 'set whatever default-props you want on your Label
End Sub
Public Property Get Caption() As String 'expose any Prop you want (Caption is obvious)
Caption = Label1.Caption
End Property
Public Property Let Caption(ByVal RHS As String)
Label1.Caption = RHS
End Property
Private Sub UserControl_Resize() 'adjust the Label1-Size according to the hosting UserControl
Label1.Move 0, 0, UserControl.Width, UserControl.Height
End Sub
Now place an instance of your new ucLabel on your Form - and check the behaviour with the following Code:
Code:
Option Explicit
Private Declare Function ReleaseCapture& Lib "user32" ()
Private Declare Function SendMessageA& Lib "user32" (ByVal hWnd&, ByVal Msg&, ByVal wParam&, lParam As Any)
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
ReleaseCapture
SendMessageA hWnd, &H112, &HF012&, 0&
End Sub
HTH
Olaf
-
Apr 9th, 2017, 01:46 PM
#2
Re: WithEvents (or something like it)
Hmmm, actually, my drawing objects (Shapes and Lines) aren't a problem. They're already handled correctly.
So, that takes me back to my labels, and Olaf has me thinking. If I just disable them, they work like I want. However, then the text is grayed, which I don't want.
I'm now wondering if there's some way to stop an Label.Enabled = False from tampering with the label's color. That's almost worth asking in a different thread, but I'll continue on here.
EDIT1: Maybe some temporary sub-classing would get this done. I'm looking into that: Leave them enabled in the IDE, call my class, do some sub-classing, explore all my controls and disabling the labels but putting the color back, undo the sub-classing, return to program.
Last edited by Elroy; Apr 9th, 2017 at 01:50 PM.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
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
|