scroll - VB.Net: Space between dynamically added controls on form increases if you pause -


purpose:
create textboxes , labels dynamically , place them on form. i've enabled autoscroll setting on form able see controls.

problem:
clicking 'add' button without more seconds pause creates no problem. however, @ (random) point space between controls become arbitrarily large. seems have amount of time wait click button reason.

more details:

  • there no timer on form, don't see how factor 'time' have any effect on spacing
  • the variable affecting position of controls number of controls added (which i've checked during run-time - checks out). rest constants.
  • i've tried same on panel. same problem occurrs.
  • it never same unwanted distance added, seems increasing longer wait.

my form:

public class form1       'public     public mytextbox, boxes(0), minboxes(0), maxboxes(0), cusboxes(0) textbox     public lngtextboxcount, lngcusboxcount long     public mylabel label      'local       'settings     public lngantaltests long = 10000      public const lngtextboxheight long = 20     public const lngtextboxlength long = 100     public const lngtextboxcuslength = 300     public const lngtextboxleft long = 20     public const lngtextboxspace long = 40     public const lngtextboxverticalspace long = 30     public const lnglabelindent long = 3      'enums     public enum boxtype         intmin         intmax         label         custom     end enum      public enum variabletype         numeric         custom     end enum      'buttons     private sub btnaddsinglenumeric_click(sender object, e eventargs) handles btnaddsinglenumeric.click         call mdladdcontrol.addsinglecontrol(variabletype.numeric)     end sub      private sub btnaddsinglecustom_click(sender object, e eventargs) handles btnaddsinglecustom.click         call mdladdcontrol.addsinglecontrol(variabletype.custom)     end sub      'load sub     private sub form1_load(sender object, e eventargs) handles mybase.load         call initialscript()          txtantal.text = cstr(lngantaltests)      end sub      private sub initialscript()         lngtextboxcount = 0         lngcusboxcount = 0     end sub   end class 

my module:

module mdladdcontrol     public sub addsinglecontrol(byval vartype form1.variabletype)         form1.lngtextboxcount += 1         select case vartype             case form1.variabletype.numeric                 call addtextbox(form1.boxtype.label, form1.variabletype.numeric)                 call addtextbox(form1.boxtype.intmin, form1.variabletype.numeric)                 call addtextbox(form1.boxtype.intmax, form1.variabletype.numeric)             case form1.variabletype.custom                 call addtextbox(form1.boxtype.custom, form1.variabletype.custom)         end select     end sub      'tools       public sub addtextbox(byval boxtype form1.boxtype, byval vartype form1.variabletype)         form1.mytextbox = new textbox         form1.mytextbox             .height = form1.lngtextboxheight             .width = form1.lngtextboxlength             .left = form1.lngtextboxleft             .top = (form1.lngtextboxheight + form1.lngtextboxspace) * form1.lngtextboxcount             select case vartype                 case vartype.custom                     form1.lngcusboxcount += 1                     .width = form1.lngtextboxcuslength                     redim preserve form1.cusboxes(form1.lngcusboxcount - 1)                     form1.cusboxes(form1.lngcusboxcount - 1) = form1.mytextbox                 case vartype.numeric                     .width = form1.lngtextboxlength                     select case boxtype                         case form1.boxtype.label                             .left = form1.lngtextboxleft                             redim preserve form1.boxes(form1.lngtextboxcount - 1)                             form1.boxes(form1.lngtextboxcount - 1) = form1.mytextbox                         case form1.boxtype.intmin                             .left = .width + form1.lngtextboxverticalspace + form1.lngtextboxleft                             redim preserve form1.minboxes(form1.lngtextboxcount - 1)                             form1.minboxes(form1.lngtextboxcount - 1) = form1.mytextbox                         case form1.boxtype.intmax                             .left = .width * 2 + form1.lngtextboxverticalspace * 2 + form1.lngtextboxleft                             redim preserve form1.maxboxes(form1.lngtextboxcount - 1)                             form1.maxboxes(form1.lngtextboxcount - 1) = form1.mytextbox                     end select             end select             call placelabel(form1.lngtextboxcount, boxtype, vartype)         end         form1.controls.add(form1.mytextbox)     end sub      public sub placelabel(byval lngtextboxnumber long, byval boxtype form1.boxtype, byval vartype form1.variabletype)         form1.mylabel = new label         form1.mylabel             .top = (form1.lngtextboxheight + form1.lngtextboxspace) * lngtextboxnumber - 24             select case boxtype                 case form1.boxtype.label                     .text = "variable label" & lngtextboxnumber - form1.lngcusboxcount                     .left = form1.lngtextboxleft - form1.lnglabelindent                 case form1.boxtype.intmin                     .text = "minimum interval"                     .left = form1.lngtextboxlength + form1.lngtextboxverticalspace + form1.lngtextboxleft - form1.lnglabelindent                 case form1.boxtype.intmax                     .text = "maximum interval"                     .left = form1.lngtextboxlength * 2 + form1.lngtextboxverticalspace * 2 + form1.lngtextboxleft - form1.lnglabelindent                 case form1.boxtype.custom                     .text = "custom code " & form1.lngcusboxcount                     .left = form1.lngtextboxleft - form1.lnglabelindent             end select         end         form1.controls.add(form1.mylabel)     end sub  end module 

thanks in advance help!


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -