2016年9月23日星期五

[Solution] Create a Class Module for MouseMove

Create a Class Module for MouseMove

Ok, after messing with for awhile I got the module to work using the the .Tag property and it works great.
The label boxes I want to change I use a "?" in its tag and it doesn't matter what the name is and the Image I use a "*" in its .Tag property
for the border to work. 
My question is, right now in my forms module I'm using a lot of MouseMoves for these controls, can I create a Class Module that can be used for the MouseMove of these Labels and Images and a Userform Mousemove for restore? I tried messing with but I'm
not knowing where to start. Below is what I have.
The module works fine its the Class that doesnt.

Standard Module......

Option Explicit Sub ControlColorChange(ctrl As Control)

If TypeName(ctrl) = "Label" And ctrl.Tag = "?" Then

ctrl.ForeColor = &H80FF& 
ctrl.Font.Size = 9
ctrl.Font.Bold = True
 End If
 If TypeName(ctrl) = "Image" And ctrl.Tag = "*"
Then
ctrl.BorderColor = &H80FF& 
 End If 
End sub




RestoreControlColours(UsForm As UserForm)
Dim ctrl As Control 
For Each ctrl In UsForm.Controls 
 If TypeName(ctrl) = "Label" And ctrl.Tag = "?"
Then
ctrl.ForeColor = &HA76C42 
ctrl.Font.Size = 8 
ctrl.Font.Bold = False 
 End If 

If TypeName(ctrl) = "Image" And ctrl.Tag = "*" Then 

ctrl.BorderColor = &HF5EFEA 

End If 

Next ctrl

End Sub


Class Module (Doesn't Work)

Option Explicit
Public WithEvents ALabel As MSForms.label
Public WithEvents BImage As MSForms.Image

Private Sub ALabel_MouseMove(ByVal Button
As Integer, ByVal Shift As Integer,
ByVal X As Single, ByVal Y As Single)
 ControlColorChange ALabel 
End Sub 
Private Sub BImage_MouseMove(ByVal Button
As Integer, ByVal Shift As Integer,
ByVal X As Single, ByVal Y As Single)
 ControlColorChange BImage 
End Sub
Private Sub UserForm_MouseMove(ByVal Button
As Integer, ByVal Shift As Integer,
ByVal X As Single, ByVal Y As Single) RestoreControlColours Me
End Sub

Solutions to the Problem Create a Class Module for MouseMove

Download SmartPCFixer for Free Now

Please unmark my previous reply - it doesn't solve your problem.
Perhaps this one will.
 
Class module:
 
Option Explicit

Public WithEvents ALabel As MSForms.Label
Public WithEvents BImage As MSForms.Image
Public WithEvents UForm As MSForms.UserForm

Private Sub ALabel_MouseMove(ByVal Button As Integer, _
        ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    ControlColorChange ALabel
End Sub

Private Sub BImage_MouseMove(ByVal Button As Integer, _
        ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    ControlColorChange BImage
End Sub

Private Sub UForm_MouseMove(ByVal Button As Integer, _
        ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    RestoreControlColours UForm
End Sub
 
Standard module:
 
Option Explicit

Public cls() As New clsEvent ' Replace with the name of your class module

Sub ControlColorChange(ctrl As MSForms.Control)
    If TypeName(ctrl) = "Label" And ctrl.Tag = "?" Then
        ctrl.ForeColor = &H80FF&
        ctrl.Font.Size = 9
        ctrl.Font.Bold = True
    End If
    If TypeName(ctrl) = "Image" And ctrl.Tag = "*" Then
        ctrl.BorderColor = &H80FF&
    End If
End Sub

Sub RestoreControlColours(UsForm As MSForms.UserForm)
    Dim ctrl As MSForms.Control
    For Each ctrl In UsForm.Controls
        If TypeName(ctrl) = "Label" And ctrl.Tag = "?" Then
            ctrl.ForeColor = &HA76C42
            ctrl.Font.Size = 8
            ctrl.Font.Bold = False
        End If
        If TypeName(ctrl) = "Image" And ctrl.Tag = "*" Then
            ctrl.BorderColor = &HF5EFEA
        End If
    Next ctrl
End Sub

Sub ShowForm()
    Dim n As Long
    Dim ctrl As MSForms.Control
    For Each ctrl In UserForm1.Controls
        If TypeName(ctrl) = "Label" And ctrl.Tag = "?" Then
            n = n + 1
            ReDim Preserve cls(1 To n)
            Set cls(n).ALabel = ctrl
        End If
        If TypeName(ctrl) = "Image" And ctrl.Tag = "*" Then
            n = n + 1
            ReDim Preserve cls(1 To n)
            Set cls(n).BImage = ctrl
        End If
    Next ctrl
    n = n + 1
    ReDim Preserve cls(1 To n)
    Set cls(n).UForm = UserForm1
    UserForm1.Show
End Sub
 
 
Change clsEvents to the name of the class module and UserForm1 to the name of the userform.

In this method we will try to Boot in Safe mode with Networking and see if the error still persists.

  • Search "MSCONFIG" and Open.
  • Click on Boot Tab
  • Tick Safe Boot in Boot Option
  • Select Network.
  • Click Apply and OK.
  • Reboot your System.

Another Safe way to Fix the Problem: Create a Class Module for MouseMove:

How to Fix Create a Class Module for MouseMove with SmartPCFixer?

1. Download Error Fixer. Install it on your computer.

2. After the scan is done, you can see the errors and problems which need to be fixed.

3. The Repair part is finished, the speed of your computer will be much higher than before and the errors have been removed. You can also use other functions in SmartPCFixer. Like dll downloading, windows updating and print spooler error repair.


Related: How Can You Update & Download NVidia 6100, 6800 GS/XT Display Driver v.260.89 WHQL,Where to Download NVidia GeForce 8800 GT WHQL-certified driver v.196.21,How to Update & Download NVidia GeForce Go 7400 Display Driver v.260.19.12,[Solved] Download NVidia GeForce GTX 460M Driver v.331.82,Download NVidia Quadro Plex Model IV VGA Driver v.304.43 Certified,Way to Download RealTek RTL8100C(L) Driver v.5.01,Way to Download RealTek RTL8100E Drivers v.694,Way to Update & Download RealTek RTL8101L Auto Installation Program v.6.110 driver,Method to Update & Download RealTek RTL8111G PXE and RPL ROM code v.2.58 driver,How to Update & Download RealTek RTL8411B(N) Driver v.10.003,Best Way to Update & Download ASUS A53SV nVidia Graphics Driver v.8.17.12.6686,Method to Herunterladen ASUS K75VJ Intel Rapid Storage Technology Treiber v.11.6.0.1030,How Can You Update & Download ASUS CG8580 Intel Chipset Driver v.9.3.0.1019,Method to Update & Download ASUS K41VD Intel INF Update Driver v.9.1.1.1015,Way to Update & Download ASUS Pro70T NB Probe v.3.0.0026 driver
Read More: [Solution] Constant Crashes with PsychReport software,Create macro for Vlookup till last data only [Anwsered],How to Fix Error - Creative Zen Vision M 30GB, Windows 7, "Device driver was not successfully installed"?,Tech Support: Copying and pasting text from a cell results in a series of small boxes,Troubleshoot:CPU runs at 100% all the time since I installed Windows 7 Error,Closing Internet Explorer causes error,Compare 2 Tables and Calculate the PROFIT Faster,Computer goes to Windows Boot Manager after Start,Connect to one of my network computer remotely when don't allow exception box Marked,computer locking up randomly

没有评论:

发表评论

注意:只有此博客的成员才能发布评论。