delphi - Flickering when TPageControl has many tabs -
my problem have tpagecontrol
contains dynamically created number of tabs each containing single (alclient
) tmemo
. when number of tabs exceeds width of control , scroll arrows appear on tab header, (well large number) of controls start flicker lot. flicker occurs when pagecontrol visible once scroll out of view of tpagecontrol
stops. when pagecontrol resized scroll arrows no longer required see of tabs flickering stops.
i'm confident problem caused scroll arrows causing painting occur because when set tpagecontrol.multiline
true there no flickering. ideally wouldn't want use multiline tabs , hope can provide solution.
information form layout
i have (personal details) form contains number of tspeedbuttons
, tlabels
, tedits
, timage
, on. many of these elements inside of tscrollbox
, grouped sections using tpanels
. panels set altop
in scrollbox , have autosize set true height never changes.
i have tried setting controls have doublebuffered
set true possible , parentbackground/color = false
sadly nothing works.
i had flickering issues before adding pagecontrols , using david's quick hack answer here tlabel , tgroupbox captions flicker on resize able improve flickering when resizing form. extending tlabel , removing background clearing paint procedure, recommended somewhere else, able 99% remove labels flickering when scrolling scrollbox have new flickering problem.
---edit---
here link stripped down version of form flickering occurring flickering example
personnel.detailsform.pas
unit personnel.detailsform; interface uses winapi.windows, winapi.messages, system.sysutils, system.variants, system.classes, vcl.graphics, vcl.controls, vcl.forms, vcl.dialogs, vcl.extctrls, system.actions, vcl.actnlist, vcl.buttons, vcl.stdctrls, vcl.comctrls, vcl.winxctrls, vcl.imaging.jpeg; type tpersonneldetailsform = class(tform) scrollbox_content: tscrollbox; panel_addressdetails: tpanel; gpanel_address: tgridpanel; edit_homemobilephone: tedit; edit_hometown: tedit; edit_homestreet: tedit; edit_homephone: tedit; lbl_homestreet: tlabel; lbl_homephone: tlabel; lbl_mobilephone: tlabel; lbl_hometown: tlabel; edit_homestate: tedit; edit_homeemail: tedit; edit_homecountry: tedit; edit_homefax: tedit; lbl_homestate: tlabel; lbl_fax: tlabel; lbl_email: tlabel; lbl_homecountry: tlabel; edit_homepostcode: tedit; lbl_homepostcode: tlabel; panel_homeaddresstitle: tpanel; panel_generalnotesdetails: tpanel; gpanel_generalnotesdetails_: tgridpanel; pagecontrol_generalnotes: tpagecontrol; procedure formclose(sender: tobject; var action: tcloseaction); procedure formshow(sender: tobject); procedure formmousewheel(sender: tobject; shift: tshiftstate; wheeldelta: integer; mousepos: tpoint; var handled: boolean); private { private declarations } public { public declarations } end; var personneldetailsform: tpersonneldetailsform; implementation {$r *.dfm} uses system.math, system.dateutils, system.threading, system.regularexpressions, system.strutils, system.contnrs, system.uitypes, system.types, winapi.shellapi, vcl.extdlgs; procedure enablecomposited(wincontrol: twincontrol); var i: integer; newexstyle: dword; begin newexstyle := getwindowlong(wincontrol.handle, gwl_exstyle) or ws_ex_composited; setwindowlong(wincontrol.handle, gwl_exstyle, newexstyle); := 0 wincontrol.controlcount - 1 if wincontrol.controls[i] twincontrol enablecomposited(twincontrol(wincontrol.controls[i])); end; procedure tpersonneldetailsform.formclose(sender: tobject; var action: tcloseaction); begin // close form , make sure frees action := cafree; // should allow free on close self.release; // sends release message backup end; procedure tpersonneldetailsform.formmousewheel(sender: tobject; shift: tshiftstate; wheeldelta: integer; mousepos: tpoint; var handled: boolean); var ltopleft, ltopright, lbottomleft, lbottomright: integer; lpoint: tpoint; begin handled := true; // first have position of control on screen // mousepos coordinates based on screen positions. lpoint := self.scrollbox_content.clienttoscreen(point(0, 0)); ltopleft := lpoint.x; ltopright := ltopleft + self.scrollbox_content.width; lbottomleft := lpoint.y; lbottomright := lbottomleft + self.scrollbox_content.width; if (mousepos.x >= ltopleft) , (mousepos.x <= ltopright) , (mousepos.y >= lbottomleft) , (mousepos.y <= lbottomright) begin // if mouse inside scrollbox coordinates, // scroll setting .vertscrollbar.position. self.scrollbox_content.vertscrollbar.position := self.scrollbox_content.vertscrollbar.position - wheeldelta; handled := true; end; if findvclwindow(mousepos) tcombobox handled := true; end; procedure tpersonneldetailsform.formshow(sender: tobject); var memo: tmemo; tabsheet: ttabsheet; ii: integer; begin ii := 0 7 begin memo := tmemo.create(self); memo.align := talign.alclient; memo.readonly := true; memo.scrollbars := tscrollstyle.ssvertical; memo.parentcolor := false; tabsheet := ttabsheet.create(self); tabsheet.insertcontrol(memo); tabsheet.pagecontrol := self.pagecontrol_generalnotes; tabsheet.caption := 'a new tabsheet ' + inttostr(ii); tabsheet.tag := ii; memo.text := 'a new memo ' + inttostr(ii); end; enablecomposited(self); self.scrollbox_content.scrollinview(self.panel_addressdetails); self.invalidate; end; end.
personnel.detailsform.dfm
object personneldetailsform: tpersonneldetailsform left = 0 top = 0 caption = 'personnel details form' clientheight = 371 clientwidth = 800 color = clbtnface doublebuffered = true font.charset = default_charset font.color = clwindowtext font.height = -13 font.name = 'segoe ui' font.style = [] oldcreateorder = false onclose = formclose onmousewheel = formmousewheel onshow = formshow pixelsperinch = 96 textheight = 17 object scrollbox_content: tscrollbox left = 0 top = 0 width = 800 height = 371 vertscrollbar.smooth = true vertscrollbar.tracking = true align = alclient taborder = 0 object panel_addressdetails: tpanel tag = 101 left = 0 top = 0 width = 796 height = 174 align = altop padding.left = 5 padding.top = 5 padding.right = 5 padding.bottom = 5 parentbackground = false taborder = 0 object gpanel_address: tgridpanel left = 6 top = 30 width = 784 height = 138 align = alclient bevelouter = bvnone columncollection = < item sizestyle = ssabsolute value = 105.000000000000000000 end item value = 50.000762951094850000 end item sizestyle = ssabsolute value = 105.000000000000000000 end item value = 49.999237048905160000 end> controlcollection = < item column = 3 control = edit_homemobilephone row = 1 end item column = 1 control = edit_hometown row = 1 end item column = 1 control = edit_homestreet row = 0 end item column = 3 control = edit_homephone row = 0 end item column = 0 control = lbl_homestreet row = 0 end item column = 2 control = lbl_homephone row = 0 end item column = 2 control = lbl_mobilephone row = 1 end item column = 0 control = lbl_hometown row = 1 end item column = 1 control = edit_homestate row = 2 end item column = 3 control = edit_homeemail row = 2 end item column = 1 control = edit_homecountry row = 3 end item column = 3 control = edit_homefax row = 3 end item column = 0 control = lbl_homestate row = 2 end item column = 2 control = lbl_fax row = 3 end item column = 2 control = lbl_email row = 2 end item column = 0 control = lbl_homecountry row = 3 end item column = 1 control = edit_homepostcode row = 4 end item column = 0 control = lbl_homepostcode row = 4 end> padding.left = 1 padding.top = 1 padding.right = 1 padding.bottom = 1 rowcollection = < item sizestyle = ssabsolute value = 27.000000000000000000 end item sizestyle = ssabsolute value = 27.000000000000000000 end item sizestyle = ssabsolute value = 27.000000000000000000 end item sizestyle = ssabsolute value = 27.000000000000000000 end item sizestyle = ssabsolute value = 27.000000000000000000 end> taborder = 0 object edit_homemobilephone: tedit left = 498 top = 29 width = 284 height = 25 align = alclient bevelinner = bvnone bevelouter = bvnone taborder = 6 text = 'mobile phone' end object edit_hometown: tedit left = 107 top = 29 width = 284 height = 25 align = alclient bevelinner = bvnone bevelouter = bvnone taborder = 1 text = 'home town' end object edit_homestreet: tedit left = 107 top = 2 width = 284 height = 25 align = alclient bevelinner = bvnone bevelouter = bvnone taborder = 0 text = 'home street' end object edit_homephone: tedit left = 498 top = 2 width = 284 height = 25 align = alclient bevelinner = bvnone bevelouter = bvnone taborder = 5 text = 'home phone' end object lbl_homestreet: tlabel left = 2 top = 2 width = 103 height = 25 align = alclient alignment = tarightjustify caption = 'street: ' color = clbtnface font.charset = default_charset font.color = clwindowtext font.height = -13 font.name = 'segoe ui' font.style = [fsbold] parentcolor = false parentfont = false transparent = true layout = tlcenter explicitleft = 61 explicitwidth = 44 explicitheight = 17 end object lbl_homephone: tlabel left = 393 top = 2 width = 103 height = 25 align = alclient alignment = tarightjustify caption = 'home phone: ' font.charset = default_charset font.color = clwindowtext font.height = -13 font.name = 'segoe ui' font.style = [fsbold] parentfont = false layout = tlcenter explicitleft = 408 explicitwidth = 88 explicitheight = 17 end object lbl_mobilephone: tlabel left = 393 top = 29 width = 103 height = 25 align = alclient alignment = tarightjustify caption = 'mobile phone: ' font.charset = default_charset font.color = clwindowtext font.height = -13 font.name = 'segoe ui' font.style = [fsbold] parentfont = false layout = tlcenter explicitleft = 402 explicitwidth = 94 explicitheight = 17 end object lbl_hometown: tlabel left = 2 top = 29 width = 103 height = 25 align = alclient alignment = tarightjustify caption = 'town: ' color = clbtnface font.charset = default_charset font.color = clwindowtext font.height = -13 font.name = 'segoe ui' font.style = [fsbold] parentcolor = false parentfont = false transparent = true layout = tlcenter explicitleft = 64 explicitwidth = 41 explicitheight = 17 end object edit_homestate: tedit left = 107 top = 56 width = 284 height = 25 align = alclient bevelinner = bvnone bevelouter = bvnone taborder = 2 text = 'home state' end object edit_homeemail: tedit left = 498 top = 56 width = 284 height = 25 align = alclient bevelinner = bvnone bevelouter = bvnone taborder = 7 text = 'home email' end object edit_homecountry: tedit left = 107 top = 83 width = 284 height = 25 align = alclient bevelinner = bvnone bevelouter = bvnone taborder = 3 text = 'home country' end object edit_homefax: tedit left = 498 top = 83 width = 284 height = 25 align = alclient bevelinner = bvnone bevelouter = bvnone taborder = 8 text = 'home fax' end object lbl_homestate: tlabel left = 2 top = 56 width = 103 height = 25 align = alclient alignment = tarightjustify caption = 'state: ' color = clbtnface font.charset = default_charset font.color = clwindowtext font.height = -13 font.name = 'segoe ui' font.style = [fsbold] parentcolor = false parentfont = false transparent = true layout = tlcenter explicitleft = 66 explicitwidth = 39 explicitheight = 17 end object lbl_fax: tlabel left = 393 top = 83 width = 103 height = 25 align = alclient alignment = tarightjustify caption = 'fax: ' font.charset = default_charset font.color = clwindowtext font.height = -13 font.name = 'segoe ui' font.style = [fsbold] parentfont = false layout = tlcenter explicitleft = 467 explicitwidth = 29 explicitheight = 17 end object lbl_email: tlabel left = 393 top = 56 width = 103 height = 25 align = alclient alignment = tarightjustify caption = 'email: ' font.charset = default_charset font.color = clwindowtext font.height = -13 font.name = 'segoe ui' font.style = [fsbold] parentfont = false layout = tlcenter explicitleft = 454 explicitwidth = 42 explicitheight = 17 end object lbl_homecountry: tlabel left = 2 top = 83 width = 103 height = 25 align = alclient alignment = tarightjustify caption = 'country: ' color = clbtnface font.charset = default_charset font.color = clwindowtext font.height = -13 font.name = 'segoe ui' font.style = [fsbold] parentcolor = false parentfont = false transparent = true layout = tlcenter explicitleft = 47 explicitwidth = 58 explicitheight = 17 end object edit_homepostcode: tedit left = 107 top = 110 width = 284 height = 25 align = alclient bevelinner = bvnone bevelouter = bvnone taborder = 4 text = 'home post code' end object lbl_homepostcode: tlabel left = 2 top = 110 width = 103 height = 25 align = alclient alignment = tarightjustify caption = 'post code: ' color = clbtnface font.charset = default_charset font.color = clwindowtext font.height = -13 font.name = 'segoe ui' font.style = [fsbold] parentcolor = false parentfont = false transparent = true layout = tlcenter explicitleft = 35 explicitwidth = 70 explicitheight = 17 end end object panel_homeaddresstitle: tpanel left = 6 top = 6 width = 784 height = 24 align = altop alignment = taleftjustify bevelouter = bvnone caption = ' home address ' color = clmedgray font.charset = default_charset font.color = clwindowtext font.height = -13 font.name = 'segoe ui' font.style = [fsbold, fsunderline] parentbackground = false parentfont = false taborder = 1 end end object panel_generalnotesdetails: tpanel tag = 303 left = 0 top = 174 width = 796 height = 172 align = altop autosize = true padding.left = 5 padding.top = 5 padding.right = 5 padding.bottom = 5 parentbackground = false taborder = 1 object gpanel_generalnotesdetails_: tgridpanel left = 6 top = 6 width = 784 height = 160 align = altop bevelouter = bvnone columncollection = < item value = 100.000000000000000000 end> controlcollection = < item column = 0 control = pagecontrol_generalnotes row = 0 end> padding.left = 1 padding.top = 1 padding.right = 1 padding.bottom = 1 rowcollection = < item sizestyle = ssabsolute value = 160.000000000000000000 end> taborder = 0 object pagecontrol_generalnotes: tpagecontrol left = 2 top = 2 width = 780 height = 158 align = alclient taborder = 0 end end end end end
i figured out problem caused quick hack david answered tlabel , tgroupbox captions flicker on resize after removed mad flickering when tpagecontrol
tab scroll buttons visible went away. i'll have @ more in-depth solution , see if can of flickering seeing before.
Comments
Post a Comment