ID:1978508
 
(See the best response by Konlet.)
Well I think the title says it all. Also can that box be larger than the icon??

Edit: I'm trying to create create a box and update it each time the mouse is dragged.

icon.DrawBox() alters the pixels of an icon directly. It is a pretty slow procedure and should be used sparingly. In order to use DrawBox(), you'll need an icon to alter its pixels.
var/icon/i = icon('some_blank_icon.dmi') // let's assume it's 10x10 pixels.
i.DrawBox("#FF0000",1,1,10,10) // Draws a filled red square on the icon.
i.DrawBox("#FFFF00",5,5) // Draws a single yellow dot in the middle


Also yes the box can be larger than the icon, but won't draw any pixels that aren't within range of the dimensions.
DrawBox() isn't itself all that slow. What's slow is the overhead of the proc calls, and of loading the icon in the first place.

The box is always clipped to the icon size; you can use Crop() or Scale() to make the icon larger before you draw.
So is there any library that can draw a box on drag selection??

I've tried creating one by scaling to where the mouse pointer is and updating the box but when mouse pointer goes before icons (0,0) it won't work.

Icon manipulation is not what you want for this. I would suggest having a few line icons that you stretch to form the box.
Best response
Like Lummox said, stretching transforms of 4 pixels is the right way to go. This example is for the client.screen:
box
parent_type = /obj
New(px,py,x2,y2,FILL = FALSE)
..()
px *= world.icon_size
py *= world.icon_size
x2 *= world.icon_size
y2 *= world.icon_size
new/pixel("1:[px],1:[py]",x2-px,1,src)
new/pixel("1:[px],1:[py]",1,y2-py,src)
new/pixel("1:[x2],1:[py]",1,y2-py,src)
new/pixel("1:[px],1:[y2]",x2-px,1,src)
pixel
parent_type = /obj
icon = 'draw.dmi'
layer = MOB_LAYER + 300
New(LOC,px,py,box/box,lyr = FLOAT_LAYER)
layer = lyr
..()
var/matrix/M = matrix()
M.Translate(0.5)
M.Scale(px,py)
animate(src,transform = M,time=10)
screen_loc = LOC


The Translate is to fix the offset, since scaling is contrasted to the center.