vb.net - What would be a better way to make a calendar than using labels? -


i've created own winforms month-view calendar in vb.net.

to i've used table layout panel, 42 separate cells. in each of cells label called lblday1, lblday2, etc.

when load page, labels written correct numbers month.

 dim daysinmonthcnt integer =31 'assume 31 days  dim firstday integer = weekday("1/" & now.month & "/" & now.year) 'get weekday 1st of month  daycount integer = firstday daysinmonthcnt     dim lbl label     lbl = ctype(pnlmonthbody.controls("lblday" & daycount), label)     lbl.text = daycount 'write label  next daycount 

unfortunately, turns out incredibly slow load. can please suggest faster method.

just writing values small number of labels fast process. problems experiencing have vb.net "problems" while refreshing contents of gui controls; best way fix looking multithreading, suggested fraserofsmeg.

as far think pretty simplistic gui low number of controls , not demanding algorithm (big amount of/long loops prime cause of gui-refreshing problems), might acceptable performance without relying on multithreading. in situation, following:

  1. a container (the tablelayoutpanel using or simpler, panel) including labels @ start. in case of not getting messy (what not seem case, 42 labels) include them in "design view" (rather @ run time).
  2. a function populating labels depending upon given month.
  3. a "transition effect" container called every time user selects different month. can accomplish quite timer relocating container (e.g., when button clicked container's position set outside form , comes gradually (20 points per 10ms -> made-up numbers) until being original position).
  4. synchronising 2 points above: values of labels start changing when transition starts; in way user not notice (just nice-appealing transition month month).

this gui should deliver kind of performance after. if not, should improve performance relying on additional means (e.g., proposed multi-threading).

sample code illustrate point 3

add panel (panel1), button (button1) , timer (timer1) new form , code below.

public class form1      dim curx, origx, timerinterval, xincrease integer     dim moving boolean     private sub timer1_tick(sender system.object, e system.eventargs) handles timer1.tick         if (curx >= origx)             if (moving)                 curx = panel1.location.x                 moving = false                 timer1.stop()             else                 curx = 0 'getting out of screen                 moving = true             end if         else             curx = curx + xincrease         end if         panel1.location = new point(curx, panel1.location.y)     end sub      private sub button1_click(sender system.object, e system.eventargs) handles button1.click         timer1.start()     end sub      private sub form1_load(sender system.object, e system.eventargs) handles mybase.load          xincrease = 100         timerinterval = 100         panel1.backcolor = color.maroon         origx = panel1.location.x         curx = origx         timer1             .enabled = false             .interval = timerinterval         end      end sub end class 

this simplistic, shows idea clearly: when click button panel moves in x; affecting timerinterval , xincrease values can nice-looking transition (there lots of options, bear in mind if set curx minus width of panel, rather zero, goes outside form).


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -