Example easter: Fix ownerdrawn listbox not painting its background, center listbox items

git-svn-id: trunk@54854 -
This commit is contained in:
wp 2017-05-10 15:02:18 +00:00
parent c824f9135d
commit 7b4283dd0e
3 changed files with 99 additions and 115 deletions

View File

@ -1,19 +1,19 @@
<?xml version="1.0"?>
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<PathDelim Value="/"/>
<Version Value="6"/>
<Version Value="10"/>
<General>
<Flags>
<SaveClosedFiles Value="False"/>
<SaveOnlyProjectUnits Value="True"/>
<LRSInOutputDirectory Value="False"/>
</Flags>
<MainUnit Value="0"/>
<IconPath Value="./"/>
<TargetFileExt Value=""/>
<Title Value="holyday"/>
<ActiveEditorIndexAtStart Value="0"/>
</General>
<BuildModes Count="1">
<Item1 Name="default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<IgnoreBinaries Value="False"/>
@ -34,46 +34,46 @@
<Unit0>
<Filename Value="holyday.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="holyday"/>
<CursorPos X="4" Y="14"/>
<TopLine Value="1"/>
<EditorIndex Value="2"/>
<CursorPos X="4" Y="14"/>
<UsageCount Value="23"/>
<Loaded Value="True"/>
<LoadedDesigner Value="True"/>
</Unit0>
<Unit1>
<Filename Value="main.pas"/>
<ComponentName Value="Form1"/>
<IsPartOfProject Value="True"/>
<ResourceFilename Value="main.lrs"/>
<ComponentName Value="Form1"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="Main"/>
<CursorPos X="13" Y="20"/>
<TopLine Value="1"/>
<EditorIndex Value="0"/>
<IsVisibleTab Value="True"/>
<TopLine Value="114"/>
<CursorPos Y="121"/>
<UsageCount Value="23"/>
<Loaded Value="True"/>
<LoadedDesigner Value="True"/>
</Unit1>
<Unit2>
<Filename Value="about.pas"/>
<ComponentName Value="AboutBox"/>
<IsPartOfProject Value="True"/>
<ResourceFilename Value="about.lrs"/>
<UnitName Value="about"/>
<CursorPos X="23" Y="26"/>
<TopLine Value="1"/>
<ComponentName Value="AboutBox"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<EditorIndex Value="1"/>
<CursorPos X="48" Y="13"/>
<UsageCount Value="23"/>
<Loaded Value="True"/>
<LoadedDesigner Value="True"/>
</Unit2>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="8"/>
<SearchPaths>
</SearchPaths>
<Other>
<CompilerPath Value="$(CompPath)"/>
</Other>
<Version Value="11"/>
<Parsing>
<SyntaxOptions>
<UseAnsiStrings Value="False"/>
</SyntaxOptions>
</Parsing>
</CompilerOptions>
</CONFIG>

View File

@ -1,152 +1,134 @@
object Form1: TForm1
BorderStyle = bsDialog
Caption = 'Holy Days'
ClientHeight = 195
ClientWidth = 430
OnCreate = Form1CREATE
OnShow = Form1SHOW
PixelsPerInch = 96
Position = poDesktopCenter
HorzScrollBar.Page = 429
VertScrollBar.Page = 194
Left = 392
Height = 195
Top = 213
Width = 430
HorzScrollBar.Page = 429
VertScrollBar.Page = 194
BorderStyle = bsDialog
Caption = 'Holy Days'
ClientHeight = 195
ClientWidth = 430
OnShow = Form1SHOW
Position = poDesktopCenter
LCLVersion = '1.9.0.0'
object Bevel1: TBevel
BorderSpacing.OnChange = nil
Height = 165
Left = 13
Name = 'Bevel1'
Height = 173
Top = 14
Width = 282
Shape = bsFrame
Top = 11
Width = 282
Left = 13
Height = 165
Top = 11
Width = 282
end
object AshWednesdayLabel: TLabel
BorderSpacing.OnChange = nil
Caption = 'Aschermittwoch:'
Color = clNone
Left = 24
Height = 13
Height = 15
Top = 64
Width = 80
Width = 90
Caption = 'Aschermittwoch:'
ParentColor = False
end
object YearLabel: TLabel
BorderSpacing.OnChange = nil
Caption = 'Jahr'
Color = clNone
Left = 24
Height = 13
Height = 15
Top = 24
Width = 21
Caption = 'Jahr'
ParentColor = False
end
object GoodFridayLabel: TLabel
BorderSpacing.OnChange = nil
Caption = 'Karfreitag:'
Color = clNone
Left = 24
Height = 13
Height = 15
Top = 81
Width = 52
Width = 54
Caption = 'Karfreitag:'
ParentColor = False
end
object EasterMondayLabel: TLabel
BorderSpacing.OnChange = nil
Caption = 'Ostermontag'
Color = clNone
Left = 24
Height = 13
Height = 15
Top = 98
Width = 63
Width = 70
Caption = 'Ostermontag'
ParentColor = False
end
object AscensionDayLabel: TLabel
BorderSpacing.OnChange = nil
Caption = 'Himmelfahrt'
Color = clNone
Left = 24
Height = 13
Height = 15
Top = 115
Width = 57
Width = 68
Caption = 'Himmelfahrt'
ParentColor = False
end
object PentecostLabel: TLabel
BorderSpacing.OnChange = nil
Caption = 'Pfingsten'
Color = clNone
Left = 24
Height = 13
Height = 15
Top = 132
Width = 45
Width = 50
Caption = 'Pfingsten'
ParentColor = False
end
object CorpusCristiLabel: TLabel
BorderSpacing.OnChange = nil
Caption = 'Fronleichnam'
Color = clNone
Left = 24
Height = 13
Height = 15
Top = 149
Width = 63
Width = 73
Caption = 'Fronleichnam'
ParentColor = False
end
object CalculateButton: TButton
BorderSpacing.OnChange = nil
Caption = 'Berechne'
OnClick = Button1CLICK
TabOrder = 0
Left = 312
Height = 35
Top = 56
Width = 104
Caption = 'Berechne'
OnClick = Button1CLICK
TabOrder = 0
end
object Listbox1: TListBox
BorderSpacing.OnChange = nil
ItemHeight = 17
OnDrawItem = Listbox1DrawItem
Style = lbOwnerDrawFixed
TabOrder = 1
Left = 136
Height = 108
Top = 62
Width = 141
ItemHeight = 17
OnDrawItem = Listbox1DrawItem
Options = [lboDrawFocusRect]
Style = lbOwnerDrawFixed
TabOrder = 1
end
object Edit1: TEdit
BorderSpacing.OnChange = nil
TabOrder = 2
Text = '2003'
Left = 136
Height = 23
Top = 24
Width = 141
Alignment = taRightJustify
TabOrder = 2
Text = '2017'
end
object EndButton: TButton
BorderSpacing.OnChange = nil
Caption = 'Ende'
OnClick = Button2CLICK
TabOrder = 3
Left = 312
Height = 35
Top = 104
Width = 104
Caption = 'Ende'
OnClick = Button2CLICK
TabOrder = 3
end
object AboutButton: TButton
BorderSpacing.OnChange = nil
Caption = 'Info'
OnClick = Button3CLICK
TabOrder = 4
Left = 312
Height = 35
Top = 152
Width = 104
Caption = 'Info'
OnClick = Button3CLICK
TabOrder = 4
end
object LanguageButton: TButton
BorderSpacing.OnChange = nil
Caption = 'English'
OnClick = LanguageButtonCLICK
TabOrder = 5
Left = 312
Height = 35
Top = 8
Width = 104
Caption = 'English'
OnClick = LanguageButtonCLICK
TabOrder = 5
end
end

View File

@ -30,11 +30,10 @@ TYPE
PROCEDURE Button1CLICK(Sender: TObject);
PROCEDURE Button2CLICK(Sender: TObject);
PROCEDURE Button3CLICK(Sender: TObject);
procedure Form1CREATE(Sender: TObject);
PROCEDURE Form1SHOW(Sender: TObject);
procedure LanguageButtonCLICK(Sender: TObject);
procedure Listbox1DrawItem(Control: TWinControl; Index: Integer;
ARect: TRect; State: TOwnerDrawState);
procedure Listbox1DrawItem(AControl: TWinControl; Index: Integer;
ARect: TRect; AState: TOwnerDrawState);
PUBLIC
FUNCTION CalcEasterday(aYear: Word): TDateTime;
END;
@ -55,7 +54,10 @@ BEGIN
TRY
aYear := StrToInt(Edit1.Text);
EXCEPT
ShowMessage('Fehlerhafte Eingabe des Jahrs!');
if LanguageButton.Caption = 'English' then
ShowMessage('Fehlerhafte Eingabe des Jahrs!')
else
ShowMessage('Incorrect input of the year!');
Exit;
END;
Easter := CalcEasterday(aYear);
@ -77,11 +79,6 @@ begin
AboutBox.ShowModal;
end;
procedure TForm1.Form1CREATE(Sender: TObject);
begin
end;
PROCEDURE TForm1.Form1SHOW(Sender: TObject);
BEGIN
Button1CLICK(Sender);
@ -116,10 +113,15 @@ begin
end;
end;
procedure TForm1.Listbox1DrawItem(Control: TWinControl; Index: Integer;
ARect: TRect; State: TOwnerDrawState);
procedure TForm1.Listbox1DrawItem(AControl: TWinControl; Index: Integer;
ARect: TRect; AState: TOwnerDrawState);
var
ts: TTextStyle;
begin
Listbox1.Canvas.TextRect(ARect, ARect.Left+2, ARect.Top, Listbox1.Items[Index]);
Listbox1.Canvas.FillRect(ARect);
ts := Listbox1.Canvas.TextStyle;
ts.Alignment := taCenter;
Listbox1.Canvas.TextRect(ARect, ARect.Left+2, ARect.Top, Listbox1.Items[Index], ts);
end;
FUNCTION TForm1.CalcEasterday(aYear: WORD): TDateTime;