Firemonkey TListBox changing background color at runtime - firemonkey

I there a way, at runtime, other than using styles, to change the background color of a TListBox? Can I use the OnPaint event?

Because the TListbox doesn't have a property to change the background color, I can only think of the following, which is based on combining two components, of which one (the TListBox) uses a built-in style. Note however, that this is not depending on TStyleBook nor any of the style files supplied with Delphi Firemonkey.
Place a TRectangle as a background for the TListBox. Set its Fill - Color property to a color you like. (I used "Cornsilk" in the example).
Place the TListBox on the rectangle as a child of the rectangle. In the "Object Inspector" locate the StyleLookup property and change its value to transparentlistboxstyle. This makes the listbox transparent and the rectangle and its fill color to shine through.
If you make the TListBox one pixel smaller than the rectangle on each side, you can use the Sides property to provide a thin frame around the listbox. Or you can choose to make them equally sized and not show any frame.
My test result looks like this:
The TRectangle and the TListbox properties from the .fmx file:
object Rectangle1: TRectangle
Anchors = [akLeft, akTop, akBottom]
Fill.Color = claCornsilk
Position.X = 7.000000000000000000
Position.Y = 40.000000000000000000
Size.Width = 361.000000000000000000
Size.Height = 219.000000000000000000
Size.PlatformDefault = False
object ListBox1: TListBox
Anchors = [akLeft, akTop, akRight, akBottom]
Position.X = 1.000000000000000000
Position.Y = 1.000000000000000000
Size.Width = 359.000000000000000000
Size.Height = 217.000000000000000000
Size.PlatformDefault = False
StyleLookup = 'transparentlistboxstyle'
TabOrder = 0
ParentShowHint = False
ShowHint = False
DisableFocusEffect = True
ItemHeight = 48.000000000000000000
DefaultItemStyles.ItemStyle = 'listboxitemrightdetail'
DefaultItemStyles.GroupHeaderStyle = ''
DefaultItemStyles.GroupFooterStyle = ''
Viewport.Width = 359.000000000000000000
Viewport.Height = 217.000000000000000000
end
end
To change the color of ListBox1, you actually change the color of the TRectangle:
procedure TForm5.ColorListBox1ItemClick(const Sender: TCustomListBox;
const Item: TListBoxItem);
begin
Rectangle1.Fill.Color := TColorListBox(Sender).Color;
end;

Related

Remove drop shadow after hover

I need to highlight the state when mouse hovers over by adding stroke around the state and adding a drop shadow. But when hover is off, the border stroke is gone, but the drop shadow stays. Is there anyway to remove the drop shadow?
Drop shadow is implemented as a filter. Is it possible to remove a filter at all?
Sample code is here: https://codepen.io/lima01/pen/OJmqgXv
var hoverState = polygonTemplate.states.create("hover");
hoverState.properties.fill = am4core.color("#367B25");
hoverState.properties.stroke = am4core.color("#ff0000");
hoverState.properties.strokeWidth = 5;
var hoverShadow = hoverState.filters.push(new am4core.DropShadowFilter);
hoverShadow.dx = 6;
hoverShadow.dy = 6;
hoverShadow.opacity = 0.3;
Thanks!
You need to set a default filter for the polygon's default state so that it knows what to revert itself to when the hover state is no longer active. You can do this by setting a DropShadowFilter for the polygon's defaultState to with a zero opacity:
var defaultFilter = polygonTemplate.defaultState.filters.push(
new am4core.DropShadowFilter()
);
defaultFilter.opacity = 0;

Animate CALayer - zoom and scroll

I want to create an animation with CALayers.
I have a parent layer with multiple sublayers and I would like to zoom in and scroll.
First I trying to zoom on the parent layer, as follows:
let transformAnimation = CABasicAnimation(keyPath: "bounds.size.width")
transformAnimation.duration = 2.3
transformAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
transformAnimation.toValue = 650*2
transformAnimation.beginTime = CACurrentMediaTime() + 4
transformAnimation.autoreverses = false
transformAnimation.isRemovedOnCompletion = false
transformAnimation.fillMode = kCAFillModeForwards
parentLayer.add(transformAnimation, forKey: "transformAnimation")
//
let transformAnimation2 = CABasicAnimation(keyPath: "bounds.size.height")
transformAnimation2.duration = 2.3
transformAnimation2.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
transformAnimation2.toValue = 650*2 //CGAffineTransform.identity
transformAnimation2.beginTime = CACurrentMediaTime() + 4
transformAnimation2.autoreverses = false
transformAnimation2.isRemovedOnCompletion = false
transformAnimation2.fillMode = kCAFillModeForwards
parentLayer.add(transformAnimation2, forKey: "transformAnimation2")
When the animation is applied, the sublayers are left in wrong position and size. Should I also apply the animation to them?
How can I do this?
Thanks!
I'm guessing that you're updating width and height of one layer and you're wondering whether the bounds of sublayers will also change. No, you'll probably have to animate those separately, too. But rather than initiating separate animations, you can them with a CAAnimationGroup.
If these were views, you could define constraints that coordinate the resizing of subviews more gracefully. But with layers, you're going to have to do this yourself. (There might be reasons why you're doing it the way you are, but it's not clear from the question.)

Programmatically created Label will not right-justify

Creating a label programatically (i.e. not in designer) won't right-align on my form.
Set lblStatus = StatusForm.Controls.Add("VB.Label", "lbl" & xml(Prop, "column"))
With lblStatus
.Visible = True
.Caption = Text
.Alignment = vbRightJustify
.WordWrap = False
.AutoSize = True
.top = Index * (lblStatus.height)
.left = MaxWidth - Screen.TwipsPerPixelX * 15
.Width = StatusForm.TextWidth(Text)
End With
I created three of these controls, but they continue to expand from the left, rather than from the right:
Ideally, I want those labels (surrounded by #) to have their semicolons line up.
Since you set AutoSize to true, the width is set to the precise width of the text, leaving no room for alignment.
To layout the text within a fixed width, turn off AutoSize.

How do you calculate the height of the title bar in VB6?

I'm trying to display one form relative to a Button on a control below it.
But Button.top is relative to the titlebar of the bottom form, and the top form will be relative to the screen.
So, to compensate for that I need to now how tall the titlebar is.
I've used Form.height-Form.ScalehHeight but ScaleHeight doesn't include the title bar or the border so Scaleheight is inflated slightly.
Anyone know how to calculate the height of just the title bar?
You need to use the GetSystemMetrics API call to get the height of the titlebar.
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Const SM_CYCAPTION = 4
Property Get TitleBarHeight() as Long
TitleBarHeight = GetSystemMetrics(SM_CYCAPTION)
End Property
Note: This will return the height in pixels. If you need twips you will have to convert using a form's ScaleY method like so: Me.ScaleY(TitleBarHeight(), vbPixels, vbTwips)
Subtract it back out:
(Form.height-Form.ScaleHeight) - (Form.Width-Form.ScaleWidth) / 2
"Recursive's" answer above is not quite correct. It subtracts twice the border width - there is a border on the left and one on the right!
We get the best results with this:
(Form.Height-Form.ScaleHeight) - (Form.Width-Form.ScaleWidth)/2
' For completeness:
Public Const SM_CYCAPTION = 4
Public Const SM_CYBORDER = 6
Public Const SM_CYFRAME = 33
' in Pixels
Property Get NonClinetHeight()
FrameH = GetSystemMetrics(SM_CYFRAME) ' Total height, Top + Bottom
CaptionH = GetSystemMetrics(SM_CYCAPTION)
BorderH = GetSystemMetrics(SM_CYBORDER) ' Border around Client area
NonClinetHeight = FrameH + CaptionH + (BorderH * 2)
End Property
You'll probably need to make a Win32 API call to GetSystemMetrics()
You can use the ClientToScreen() windows API function to convert a point from client coordinates to screen coordinates:
Dim Position As Point
Position.x = 0
Position.y = 0
ClientToScreen Me.hWnd, Position
FormTop = Position.y
If you want to skip this and go direct to the button, you can use the button's position (in pixels):
Position.x = This.ScaleX(Button.Left, this.ScaleMode, vbPixels)
Position.Y = This.ScaleY(Button.Top, this.ScaleMode, vbPixels)
...
Or just get the buttons position using GetWindowRect()
Dim Position2 As Rect
GetClientRect Button.hWnd, Position2
Position.x = Position2.left
Position.y = Position2.top
...

Vertical Scrolling Marquee for foxpro

Could anyone could point me to some code/give me ideas on how to create a smooth scrolling vertical marquee for VFP 8 or 9?
Any help is appreciated.
Here's a quick program that will scroll messages. Put the following in a prg file and run it.
I'd make a containerScrollArea a class that encapsulates the timer, labels, and scrolling code. Give it GetNextMessage method that you can override to retrieve the messages.
* Put a container on the screen to hold our scroller
_screen.AddObject("containerScrollArea", "container")
WITH _Screen.containerScrollArea
* Size it
.Visible = .t.
.Width = 100
.Height = 100
* Add two labels, one to hold each scrolling message
.AddObject("labelScroll1", "Label")
.AddObject("labelScroll2", "Label")
* This timer will move the labels to scroll them
.AddObject("timerScroller", "ScrollTimer")
ENDWITH
WITH _Screen.containerScrollArea.labelScroll1
* The labels are positioned below the margin of the container, so they're not initially visible
.Top = 101
.Height = 100
.Visible = .t.
.WordWrap = .t.
.BackStyle= 0
.Caption = "This is the first scrolling text, which is scrolling."
ENDWITH
WITH _Screen.containerScrollArea.labelScroll2
* The labels are positioned below the margin of the container, so they're not initially visible
.Top = 200
.Height = 100
.Visible = .t.
.WordWrap = .t.
.BackStyle= 0
.Caption = "This is the second scrolling text, which is scrolling."
ENDWITH
* Start the timer, which scrolls the labels
_Screen.containerScrollArea.timerScroller.Interval = 100
DEFINE CLASS ScrollTimer AS Timer
PROCEDURE Timer
* If the first label is still in view, move it by one pixel
IF This.Parent.labelScroll1.Top > -100
This.Parent.labelScroll1.Top = This.Parent.labelScroll1.Top - 1
ELSE
* If the first label has scrolled out of view on the top of the container, move it back to the bottom.
This.Parent.labelScroll1.Top = 101
* Load some new text here
ENDIF
IF This.Parent.labelScroll2.Top > -100
* If the second label is still in view, move it by one pixel
This.Parent.labelScroll2.Top = This.Parent.labelScroll2.Top - 1
ELSE
* If the second label has scrolled out of view on the top of the container, move it back to the bottom.
This.Parent.labelScroll2.Top = 101
* Load some new text here
ENDIF
ENDPROC
ENDDEFINE
You can use Scrollable Container
Unfortunately the nature of my work leaves me no time for fooling around with graphics, however if I did I would look into using GDI+ with VFP. Here is an article to get you started

Resources