[Gambas-user] Resizeable control at run time?

Charlie Ogier charlie at cogier.com
Thu Nov 5 19:45:02 CET 2020


Hi K.,

I'm not totally sure what you are trying to accomplish but I have had a 
play and come up with the following code using PictureBoxes instead of 
ToolButtons. They aren't movable yet but one step at a time.
You could also look at my program ScreenShot that has items that you can 
move arround, it's on the Farm or available here 
<https://gambas.one/gambasfarm/?id=877&action=search>. Check out the 
video here <https://www.youtube.com/watch?v=0VZjC1pt7qU&feature=youtu.be>.
Let me know what else is needed.

'*********************************************
PictureBox1 As PictureBox
hPictureBox As PictureBox
hImg1 As Image
iStartX As Integer
iStartY As Integer
iWidth As Integer
iHeight As Integer
iName As Integer

Public Sub Form_Open()

   With Me
     .Padding = 5
     .Arrangement = Arrange.Vertical
     .Resizable = False
     .W = 500
     .H = 400
   End With

   With PictureBox1 = New PictureBox(Me) As "PictureBox1"
     .Expand = True
     .Image = New Image(.ClientWidth, .ClientHeight, Color.White)
   End With

End

Public Sub PictureBox1_MouseDown()

   iStartX = Mouse.ScreenX - PictureBox1.ScreenX
   iStartY = Mouse.ScreenY - PictureBox1.ScreenY

End

Public Sub PictureBox1_MouseDrag()

   iWidth = Mouse.X - iStartX
   iHeight = Mouse.Y - iStartY

   hImg1 = New Image(PictureBox1.ClientWidth, PictureBox1.ClientHeight, 
Color.White)

   With Paint
     .Begin(hImg1)
     .DrawRect(iStartX, iStartY, iWidth, iHeight, Color.Blue, 2)
     .End
   End With
   PictureBox1.Image = hImg1

End

Public Sub PictureBox1_MouseUp()

   PictureBox1.Image = New Image(PictureBox1.ClientWidth, 
PictureBox1.ClientHeight, Color.White)

   With hPictureBox = New PictureBox(PictureBox1) As "PictureBoxes"
     .X = iStartX
     .Y = iStartY
     .Width = iWidth
     .Height = iHeight
     .Picture = Picture["icon:/256/wizard"]
     .Mode = PictureBox.Contain
     .Background = Color.Transparent
     .Alignment = Align.Center
     .Name = Str(iName)
   End With

   Inc iName

End

Public Sub PictureBoxes_MouseDown()

   Me.Text = "PictureBox " & Str(Last.Name)

End

Public Sub PictureBoxes_Enter()

   Last.Border = Border.Solid
   Last.Raise

End

Public Sub PictureBoxes_Leave()

   Last.Border = Border.None

End
'*********************************************

Charlie


On 04/11/2020 17:56, KKing wrote:
> I currently use Picturebox and allow users to draw a rectangle around 
> an area of interest use via
>     With Paint
>         .Begin(hImg1)
>         .DrawRect((intStartX), intStartY, intFinishX - intStartX, 
> intFinishY - intStartY, Color.Blue, 2)
>         .End
>     End With
>     PictureBox1.Image = hImg1
> I then replace the drawn rectangle with a ToolbarButton (because 
> Button transparent is not transparent on LXDE (out of box)). This 
> allows users to update information about the area(s) of interest, by 
> pressing the individual buttons.
> Would it be possible to do something similar, but where the users 
> would be able to move or resize the ToolbarButton or a replacement?
> I thought might be able to use non modal Forms, I can draw multiple 
> forms on top of the main form (and transparent) but I've not found a 
> way to make them moveable or resizeable.
> K.
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20201105/3526f4b3/attachment.htm>


More information about the User mailing list