[Gambas-user] mouse

Charlie Ogier charlie at cogier.com
Thu Apr 30 18:51:26 CEST 2020


Hi Mike,

Try running this code in a new Gambas Graphical Application program: -

*' Gambas class file**
**
**Label1 As Label**
**
**Public Sub Form_Open()**
**
**  Dim PictureBox1 As PictureBox**
**
**  With Me**
**    .Arrangement = Arrange.Vertical**
**    .Height = 150**
**    .Width = 175**
**    .Padding = 5**
**    .Text = "Click!"**
**  End With**
**
**  With PictureBox1 = New PictureBox(Me) As "PictureBox1"**
**    .Mode = PictureBox.Contain**
**    .Alignment = Align.Center**
**    .Expand = True**
**    .Picture = Picture["icon:/huge/linux"]**
**  End With**
**
**  With Label1 = New Label(Me) As "Label1"**
**    .Height = 28**
**    .Text = "Click on the PictureBox"**
**    .Alignment = Align.Center**
**    .Font.Bold = True**
**  End With**
**
**End**
**
**Public Sub PictureBox1_MouseDown()**
**
**  If Mouse.Left Then Label1.Text = "You left clicked"**
**  If Mouse.Right Then Label1.Text = "You right clicked"**
**  If Mouse.Middle Then Label1.Text = "You middle clicked"**
**
**End**
*
I hope that helps,

Charlie


On 30/04/2020 10:45, Mike Crean via User wrote:
> Hi all I am trying to catch a mouse event when inside a PictureBox 
> Child when the LEFT
> MOUSE button is pressed. I can’t for the life of me see the answer and 
> it is probably staring
> me in the face.
>
>
> Public Sub Timer1_Timer()
>
>     Dim oo As PictureBox
>
>     Dim I As Integer
>
>     Dim x As Integer
>
>     I = 0
>
>     For Each oo In PictureBox1.Children
>
>         If oo Is PictureBox Then
>
>             I = I + 1
>
>             For x = 1 To I
>
>                 If Mouse.Inside(oo) Then
>
>                     If oo.Mouse.Left Then                     ' ERROR 
> Not an object
>
>                         Label7.Text = “Got oo”
>
>                     Endif
>
>                 Endif
>
>             Next
>
>         Endif
>
>     Next
>
> End
>
> Or with this I get the error. No mouse event data in Fmain 41
>
> If Mouse.Left(oo) Then ' ERROR No mouse event data in Fmain 41
>
> Label7.Text = “Got oo”
> Endif
>
> Regards
> Mike
>
>
>
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20200430/43140d33/attachment-0001.html>


More information about the User mailing list