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

View File

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

View File

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