Icons In ListView - excel

I am trying to add icons next to text in a listview, but I keep getting an error saying I need to imagelist must be initialised before it can be used.
On the form window as it loads, I have the following code:
Private Sub UserForm_Initialize()
ImageList3.ListImages.Add Key:="Koala", Picture:=LoadPicture("\images\add_icon.gif")
end sub
Then I am trying to populate the listview like this
li.ListSubItems.Add , , "Test", "Koala"
What am I doing wrong?

You need to link your ImageList to the ListView using the Icons-property. Add the following line in the UserForm_Initialize - this must be done before you populate the ListView (of course you need to adapt the name of the ListView)
Me.ListView1.Icons = ImageList3

Related

How to increase the size of a checkbox?

I'm trying to increase the size of a checkbox in my Userform.
In the properties tab, I can change the height and the width of the object but it doesn't change the size of the square. I add a picture to explain my issue.
Thank you.
#Portland Runner's comment is a good suggestion. For example, in the click event of the label (using WingDings 2) ...
Option Explicit
Private Sub Label1_Click()
If Label1.Caption = "Q" Then
Label1.Caption = "R"
Else
Label1.Caption = "Q"
End If
End Sub
There are 2 problems with the VBA checkbox:
The size of the square
The size of the caption text
My solutions:
Create a frame in which you put the checkbox object. A frame has the property Zoom. Set that property at whatever value you want. Then change the font size of the button to match the rest of the fonts in the form. The frame doesn't have to have a title, and you can select an invisible border for it. In that way, the user doesn't see it.
For whatever reason, the checkbox's text looks smaller than the rest of the objects, even though it is the same font size. My solution for this was to remove the checkbox's text and add a standard label object to the right.

Auto Size/Adjust Userform

I'm new with VBA Programming, I have a Userform with TextBoxes,Labels, and Checkboxes.
My problem is how to Auto size or adjust the form, Because I have hidden Textbox and Label, Now if I click the Button it will unhide the Texbox and Label and also it will auto size the Form and the other controls.
I don't know how to start this.
Actual Result
Let's assume there is hidden Label and Texbox between Team Name and Last Name now I click the update RadioButton it will unhide the hidden Label and Texbox and adjust the form and other controls.
Expected Result
Is there any way to do this?
Say, the space required by the control Tbx hidden at the level 90pt from the top is 30pt. Therefore all controls below it should be moved down by 30pt when Tbx is made visible, and the form's height also increased by that same measure. The code below would accomplish that while at the same time unhiding the control.
Dim Ctl As MSForms.Controls
For Each Ctl In Me.Controls
With Ctl
If .Top >= 90 Then
If .Visible = True Then
.Top = Top + 30
Else
.Visible = True
End If
End If
End With
Next Ctl
Me.Top = Top + 30
Two things would be different in practice.
You may have to hide the control again.
Your would create the control on the fly rather than keep it hidden.
If you plan on hiding the control again you would need an array of all affected control names and another array (or dimension) for their existing Tops. You would loop through all the names in the array and reset the top, like,
Me.Controls(Arr(0, i)).Top = Arr(1, i) + Iif(HideMe, 0, 30)
Look into creating the control on the fly. You should be able to simply create a copy of an existing control from which it inherits all properties. Any event code for that control needs to be prepared in advance, however.

VBA Transparent ActiveX object becomes opaque on click [duplicate]

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.

How do I make an Excel ActiveX label to be transparent ... at runtime?

I want to put a transparent label on top of a sheet in Excel, so that I can take advantage of the MouseMove event of the label to "draw cells" (aka change their fill color and so on) by mouse click / drag / etc. - since I can't do that on the cells per se.
Now everything works just fine, except that I can't make the label transparent at runtime (aka in VBA) ... while by doing exactly the same thing in Design Mode works as expected. Specifically, I have the code (more or less):
Dim MapLabel As OLEObject
On Error Resume Next
Sheet2.OLEObjects("MapLabel").Delete
Set MapLabel = Sheet2.OLEObjects.Add("Forms.Label.1")
MapLabel.name = "MapLabel"
MapLabel.Placement = xlMoveAndSize
MapLabel.Object.Caption = ""
' Problem line below
MapLabel.Object.BackStyle = fmBackStyleTransparent
' Problem line above
MapLabel.Left = Sheet2.cells(2, 6).Left
MapLabel.Top = Sheet2.cells(2, 6).Top
MapLabel.Width = Sheet2.cells(2,6).Width * 10
MapLabel.Height = Sheet2.cells(2,6).Height * 10
So, in words, I first delete the label named 'MapLabel', then recreate it (the above code goes into a "init" Sub). All the code lines except the one marked produce the desired result. The marked one does set the BackStyle property of the label to fmBackStyleTransparent ... but it doesn't actually make the label transparent. This is frustrating, because it's the same approach that works flawlessly at design time!
Do you have a solution to this? I read about solving similar problems by declaring the label as MsForms.Label or as Control, but the sheet object doesn't have those properties, plus, there are far more label properties which can be set using the OLEObject than with the help of MsForms.Label or Control.
All you need to do after this line:
MapLabel.Object.BackStyle = fmBackStyleTransparent
put this line:
ActiveSheet.Shapes(MapLabel.Name).Fill.Transparency = 1
I hope I helped.
P.S. If you need explanation i will edit my answer.
I had the same problem as you but in Word. The solution for me was to do the following:
In design mode:
Right click on the object
Navigate to Switch to automatic form/Image > Wrapping > In front of the text
Add an empty picture to your label

lwuit text area

I developed an RSS Application for two XML files and displayed it on two LWUIT Tabs. The problem is with my LWUIT TextArea, whenever I click on my ListForm (it contains titles from the RssFile), I need to display description information from the RSS File. First time I am able to display the description related to the title clicked in ListForm. If I click the ListForm the next time onwards I am able to display the same description again and again in the textarea..(Eventhough I am getting Related Description from RssFile)
Here is my Code:
private void displayCompleteNewsScreen(News detailNews) {
Label title = new Label(detailNews.getTitle());
form2.setTitleComponent(title);
String Description = detailNews.getDescription();
System.out.println("Description" + Description);//Here i am able to get different Description values Related to myList Screen but in text area it is displaying First one always
big = new TextArea();
big.setEditable(false);
big.setText(Description);
form2.addComponent(pubDate);
form2.addComponent(big);
form2.show();
}
As you are reusing form2 instance you should clear it in displayCompleteNewsScreen method. Call removeAll before calling setTitleComponent.
And don't forget to set form2 Commands again in displayCompleteNewsScreen.

Resources