vb.net - How to add picture to Dynamically created Picturebox, on a drag drop event -



vb.net - How to add picture to Dynamically created Picturebox, on a drag drop event -

i have function mentioned below. need add together n number of picturebox if user drop little image on panel. code below (on drag , drop event of form) able add together dynamic picturebox. facing 2 problems.

it adds 1 picturebox. if drag , drop something, replace image in picturebox.

i need add together new picturebox in row , column wise, depending on width of panel

public function addpic(byval pic image, byval pname string) dim pb new picturebox pb .name = pname .sizemode = pictureboxsizemode.centerimage .location = new system.drawing.point(5, 5) .size = new size(50, 50) .backgroundimagelayout = imagelayout.center .image = pic ' note can set more of picbox's properties here end thepanel.controls.add(pb) richtextbox1.controls.add(pb) ' line catches people out! 'me.controls.add(pb) pb.bringtofront() ' wire command appropriate event handler ' addhandler pb.click, addressof mypicclicked addhandler pb.mousedown, addressof picturebox_mousehover addhandler pb.mouseleave, addressof picturebox_mouseleave ' addhandler pb.paint, addressof picturebox_paint homecoming true end function

you need calculate how many images can fit in panel:

numimageswide = thepanel.actualwidth / image.width numimageshigh = thepanel.actualheight/ image.height

you can safely integer arithmetic need whole number of images fit.

then can loop on numimageswide , numimageshigh adding new picturebox each time round loop. code in current method wants go within loop - might cleaner write wrapper method loops , calls current method.

vb.net winforms

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -