I have been struggling on this one for a few days now and can not seem to work it out. I am using images as buttons, which have a mouseover effect that changes the border to GREEN when the mouse is hovered over them, apart from them flashing on hover, this works fine apart from when the problem kick in, see below for problem.
I then have an onClick event which changes the border to GREEN if that image/button is selected, this indicates that this is active as the click opens a multi page, this bit also seems to work fine as I had to put in a repaint event in as it would not work without it. UserForm1.Repaint.
The Problem I am having
Once a image/button has been selected and then de-selected the mouse over event NO longer works on the image/button that was previously selected.
Example, If I scroll the mouse over the two buttons below, their borders will change to green on hover, If I selected the WebBrowser button, its border will change to green, indicating that it is active. Once de-selected the mouse over will NO longer work on it. The de-selecting is done by selecting another button.
This is my mouse over code
Private Sub WebBrowserNewButt_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
''Set WebBrowserNewButt Border Colour Green
If WebBrowserNewButt.BorderColor <> 8435998 Then
Me.WebBrowserNewButt.BorderColor = 8435998
''Grey Borders
Me.MainMenuButton.BorderColor = -2147483627
Me.SecondMenuButton.BorderColor = -2147483627
Me.EmailButton.BorderColor = -2147483627
Me.SearchButton.BorderColor = -2147483627
Me.SaveNewButton.BorderColor = -2147483627
End If
End Sub
Onclick code
Private Sub WebBrowserNewButt_click()
Me.WebBrowserNewButt.BorderColor = 8435998 'GREEN BORDER
'GREY BORDERS, for all other images(buttons)
Me.MainMenuButton.BorderColor = -2147483627
Me.SecondMenuButton.BorderColor = -2147483627
Me.EmailButton.BorderColor = -2147483627
Me.SearchButton.BorderColor = -2147483627
Me.SaveNewButton.BorderColor = -2147483627
UserForm1.Repaint
'MULTIPAGES
Me.MultiPage1.Pages(0).Visible = True
MultiPage1.Value = 0
Me.MultiPage1.Pages(1).Visible = False
Me.MultiPage1.Pages(2).Visible = False
Me.MultiPage1.Pages(3).Visible = False
Me.MultiPage1.Pages(4).Visible = False
End Sub
What I have tried so far.
I have tried it with and without the Me. (I left it on Me.)
I have tried to google the answer
I have tried it without repaint, did not work without repaint, repaint
does cause the images to flash.
I have tried to place the change boarder colour in the multi-page, so when active that multi page is
visible = true then the image border colour will change, could not get it to work.
I removed the option of turning the borders to Grey on hover, that did not fix the problem.
The multi-pages will not have their tabs set to visible.
Please could someone advise on what to do.
As always thanks in advance.
Related
I am having an issue with flickering labels on my userform, when I do a mouse over. Some labels are grouped. I have ungrouped them but I am still having the flickering issue. For each button I have used 3 labels, 1 for background, 1 for Icon and 1 for text as nothing would position the icon and text as I wanted. See image
Apart from the flicker they work fine. I am using labels as buttons as the look better than the vba userform buttons and because, when I tried to you an image as a button, the picture would not display correct, the quality would reduce, but it is fine in a label.
The labels start to flicker when I move the mouse over them, I was looking at these as some possible solution on,Mr Excel Forum & My Original Thread on Mr Excel (there is a code at the botom of this thread), but I am not 100% sure how to change it for my labels. In the second thread that I posted there is a link to the original question which was raised by another member, within this thread they talk of label groups "LabelGroup.Parent.Parent.Controls". I have NO idea what this is and how to do it. Please could someone advise of how I can implement one of these codes with my code, useform or guide me to another solution.
My code is a simple IF statement, that works on a mouse over event
Private Sub MainMenuPageButton_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
'MainMenuPageButton border change green on mouse over
MainMenuPageButton.BorderColor = 8435998 'change boarder to green
'Grey Borders for all other labels
SearchButton.BorderColor = -2147483627
WebBrowserButton.BorderColor = -2147483627
SaveFileButton.BorderColor = -2147483627
EmailButton.BorderColor = -2147483627
LoadFileButton.BorderColor = -2147483627
Sheet2Button.BorderColor = -2147483627
Sheet3Button.BorderColor = -2147483627
Sheet12Button.BorderColor = -2147483627
End Sub
Thanks in advance
I am trying to remove the border of frame that has a lot of check boxes and I tried 'borderstyle 0 - frmborderstylenone' in the frame properties and it is not working. I have shown the frame border in the picture. I have many of these frames in a userform and each of these frames has at least 5 check boxes. kindly help me out
You may be surprised to learn the picture you provided does not have a Border. What you see is the SpecialEffect property set to fmSpecialEffectSunken.
You can set the property to fmSpecialEffectNone to remove it. It can be set manually in the project properties window or via code.
Setting the Border property to fmBorderStyleSingle while using a special effect will set fmSpecialEffectNone because borders are special effects are mutually exclusive. Enabling one will disable the other because you cannot use both at the same time. This is why setting and then removing the border works.
Following TheJeebo hint, setting the frame properties from code, this doesn't work:
Set myForm = New Userform
Set frm = myForm.Controls.Add("Forms.Frame.1", "Frame1", True)
With frm
.BorderStyle = 0
The frame border still there when the UserForm is displayed, but surprisingly this does work:
Set myForm = New Userform
Set frm = myForm.Controls.Add("Forms.Frame.1", "Frame1", True)
With frm
.BorderStyle = 1
.BorderStyle = 0
no border now.
I have a VBA/Excel that user clicks on labels (Active X - Text Label) to perform some actions. The label property is BackStyle Transparent, but when the user click, the label keep opaque, like white or whatever the BackColor property is set.
How can I keep transparent when user click on the label?
Don't use an ActiveX control for this. Any Shape can be assigned to a macro, so instead of having Click event handlers for ActiveX labels like so:
Private Sub Label2_Click()
'do stuff
End Sub
Make the handlers public, give them a meaningful name:
Public Sub BuscaPorPalavraChave()
'do stuff
End Sub
Replace the labels with TextBox shapes - make the shape fill and border transparent, right-click the shape, and select "assign macro" - then pick BuscaPorPalavraChavre. Done!
Rinse & Repeat for every label. I know, painful - but worth it!
That navigation UI looks very nice BTW =)
I came up with a different solution in case you have faced a related problem, like the transparency/opaque problem when executing a macro hovering over a transparent label but that becomes opaque when clicking on it.
The workaround consists basically in changing the visibility status when hovering in and out. It might be counterintuitive at first (Because you are making disappear the same label you are using to execute the macro) but it works really well. Let's assume we have two Active X labels overlap. Label1 is the bigger one and label2 is the smaller one, completely contained in Label1. The code I used is like:
Private Sub Label2_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Application.ScreenUpdating = False
Label2.Visible = False
Label1.Visible = True
### Put your code in here
Application.ScreenUpdating = True
End Sub
Then as you hover out label2, and assuming the labels are correctly overlap, you will hover over Label 1, now visible because you "activated it", and the following code is executed
Private Sub Label1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Application.ScreenUpdating = False
Label2.Visible = True
Label1.Visible = False
### Put your code in here
Application.ScreenUpdating = True
End Sub
Please bear in mind that you need to have a figure or button in between the two Active x labels, otherwise you will get a strange result because in the exact moment you hover over Label 2, it will disappear, leaving Label 1 beneath it which will also disappear as soon as you move, makin Label 2 appear again and ... you get the idea. This will not break the excel file but will make it make strange things like blinking or delaying the mouse movement. To prevent thus. I recommend to have that shape as a safe zone.
Hope this helps.
This will only work for the labels sender but, I need to use this also for the button sender so it can hide if the label is red only when the button is clicked.
I have 48 Seats
Private Sub Label_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Seat9.Click, Seat8.Click, Seat7.Click, Seat6.Click, Seat5.Click, Seat48.Click, Seat47.Click, Seat46.Click, Seat45.Click, Seat44.Click, Seat43.Click, Seat42.Click, Seat41.Click, Seat40.Click, Seat4.Click, Seat39.Click, Seat38.Click, Seat37.Click, Seat36.Click, Seat35.Click, Seat34.Click, Seat33.Click, Seat32.Click, Seat31.Click, Seat30.Click, Seat3.Click, Seat29.Click, Seat28.Click, Seat27.Click, Seat26.Click, Seat25.Click, Seat24.Click, Seat23.Click, Seat22.Click, Seat21.Click, Seat20.Click, Seat2.Click, Seat19.Click, Seat18.Click, Seat17.Click, Seat16.Click, Seat15.Click, Seat14.Click, Seat13.Click, Seat12.Click, Seat11.Click, Seat10.Click, Seat1.Click
Dim Seats As Label = CType(sender, Label)
If Seats.BackColor = Color.White Then
Seats.BackColor = Color.Red
Else
Seats.BackColor = Color.White
End If
Okay, I think I understand now.
You have multiple labels which represent seats and when the user clicks on the labels they change from white to red.
You are wanting to create a button that once clicked, it removes all red labels from the screen/form.
You would place the following in the click event of your button (assuming that your form is called frmMain)
For Each c As Control in frmMain.Controls
Dim l As Label = DirectCast(c, Label) ' Cast from control to label
If Not l Is Nothing ' If this control is indeed a label then process
If l.BackColor = Color.Red Then ' If color is red then hide label
l.Visible = False
Else
l.Visible = True
End If
l.Visible = False
End If
Next
I don't have VS pulled up, so syntax may be a little incorrect but I think you get the point.
A killer problem I've had in excel UIs since as long as I can remember, is with listbox scrolling.
When you have more elements in a listbox that can be displayed, a scoll bar will appear. In certain conditions, however, scrolling the bar all the way to the bottom of the list and releasing it, will "jump" the bar a notch upwards, and you won't be able to see the last item in the list. This is illustrated here:
There are many forum posts presenting this issue, and the solution has always been "Set the integral height property to false, and then set it to true again." What this does is slightly resize the listbox so that it the height is rounded to the height of a single row, and then no items are left hidden.
With lstbox
.IntegralHeight = False
.Height = myHeight
.IntegralHeight = True
End With
There are certain cases, however, where this does not work. If you are:
Programatically setting the height of your listbox
NOT using simple listbox selection (fmMultiSelectSingle)
Then simply setting integral height to false and then true after or between changes to height will make an adjustment to the height of your listbox, but when you go to scroll down, the problem will remain - the last item cannot be seen.
The key to this frustrating question is that while everyone else on the internet is confirming that the 'integralHeight' solution works for them, these very special cases are frustrated wondering why it doesn't work for them. So how do they get their fix?
Something I had to discover for myself, and which cannot be found anywhere else (which is why I'm posting it here), is that this problem had the added dimension of being dependent on the selection method. While I cannot fathom how the way the scroll bar works is related to not only the height and integral height property, but also the .MultiSelect property, I have found that it is.
When the .IntegralHeight method shown above does not work, the following method somehow does:
With lstbox
.IntegralHeight = False
.Height = myHeight
.IntegralHeight = True
.MultiSelect = fmMultiSelectSingle
.MultiSelect = fmMultiSelectExtended
End With
By simply changing the .MultiSelect property to fmMultiSelectSingle, and then restoring it back to the selection style desired, the height of the listbox will be automatically adjusted by the .IntegralHeight property to a slightly different height than when these actions aren't performed - the difference results in the scroll bar working correctly:
I hope the discovery of this special case and more precise workaround saves someone the hours of frustration and experimentation I had to go through.
i know this is very old post.
but i've been through a lot to fix this problem, so i just wanna share my tip. :)
first of all,
integralheight method doesn't work when worksheet zoom level is not 100%.
it will change listbox height and width, location, etc. (even if you set object property 'doesn't move or reseize with cell')
and when you try to take it its original size and location with code to fix this, this time its last item can't be seen
my tip is simple.
there's combination between font size and listbox height.
if your font size is 6-10(arial, regular), listbox height goes well with multiples of 12.75 (btw my list box style is 1 : ListStyle, 1-fmListStyleOption. it could be different with style 0)
as long as height is same with these multiples of 12.75, there will be no problem.
in case of font size 12(arial, regular), it's multiples of 13.55
so if there's no restiction about listbox size in your project, just resizing it slightly depending on your font size gives more comfort. :)
I had to anchor the position since my ListBox was walking across the page:
With ListBox1
.IntegralHeight = False
.IntegralHeight = True
.Height = 45
.Width = 69
.Top = 0
.Left = 1255.5
End With
With lstbox
`.Height = myHeight`
`.MultiSelect = fmMultiSelectExtended`
`.MultiSelect = fmMultiSelectSingle`
End With
This worked for me. No need of setting Integral height property
In my case the solution was this method:
with listbox
.IntegralHeight = False
.Height = myHeight
.Width = myWidth
.IntegralHeight = True
.Height = myHeight
.Width = myWidth
end with
Enjoy.
found ridiculously simple way to resolve this issue. adjust your height up or down a little bit so bottom line of list box is between check boxes, then you can scroll down to last item even if IntegralHeight is set to false
Thanks Alain. Your fix worked well for me.
I found a subsequent problem related to the height of the ListBox when resized, that it varied in an unpredictable way depending on the initial height. The resized height was different again when displayed on another machine with 125% text scaling. For example, if I set a height between 358 and 370, the resized height is either 370.65 or 371.4 on my machine but on the machine with 125% text scaling, it is 360.1, 370.25 or 380.45. With such large variability, the result was that the ListBox could obscure other controls below it.
The fix was to start with the maximum height I wanted and reduce the initial height until the resized height was less than the maximum height I wanted. I do this whenever I display that ListBox.
Hmax = 372 'Target Height
H1 = Hmax
With SteelForm.Controls.Item("ListBox1")
Do
H1 = H1 - 1
.IntegralHeight = False
.Height = H1
.IntegralHeight = True
.MultiSelect = fmMultiSelectSingle
.MultiSelect = fmMultiSelectExtended
DoEvents
Loop Until .Height < Hmax
End With
What I've seen in the past on forums is just adding an extra blank row to your list box. That should do it.
Just set the Integral Height property to True