Recent

Author Topic: Image as button  (Read 14407 times)

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
Image as button
« on: December 06, 2010, 09:38:31 am »
I want to use an image as if it were a button. What should I do because I do click on the corners when I press a button? And how do you release the button?
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
Re: Image as button
« Reply #1 on: December 06, 2010, 11:12:22 am »
Let me explain, I wish that when I go with the mouse on the image edge and turns gray when you click on the board must look to the edge of the button clicked, and when the issue should go on as before. Ideas? Suggestions?
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

Leledumbo

  • Hero Member
  • *****
  • Posts: 8835
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Image as button
« Reply #2 on: December 06, 2010, 01:12:38 pm »
I still don't quite understand actually. Just use TImage and its OnClick property. What else do you need?

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
Re: Image as button
« Reply #3 on: December 06, 2010, 01:26:34 pm »
An example. I do not know how to handle the edge TImage object like a button!
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Image as button
« Reply #4 on: December 06, 2010, 01:48:46 pm »
You could draw two images on an image editor and use them to simulate button up and down.

Use OnMouseDown and OnMouseUp event handlers.
« Last Edit: December 06, 2010, 01:53:43 pm by typo »

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
Re: Image as button
« Reply #5 on: December 06, 2010, 01:58:55 pm »
Thank you
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

ivan17

  • Full Member
  • ***
  • Posts: 173
Re: Image as button
« Reply #6 on: December 06, 2010, 08:54:13 pm »
You could draw two images on an image editor and use them to simulate button up and down.

well if you're there, it's a shame not to use three images (one for hover). here's an example - add to TImage components to the form, load a 75x75 image into the first (component size can be anything, even 0x0) and set the size of second TImage to 75x25. then add the following:
Image2MouseDown
  Image2.Canvas.CopyRect(Rect(0, 0, 75, 25), Image1.Canvas, Rect(0, 50, 75, 75))

Image2MouseEnter
  Image2.Canvas.CopyRect(Rect(0, 0, 75, 25), Image1.Canvas, Rect(0, 25, 75, 50))

Image2MouseLeave  (call this one from FormCreate)
  Image2.Canvas.CopyRect(Rect(0, 0, 75, 25), Image1.Canvas, Rect(0, 0, 75, 25))

Image2MouseUp
  if PtInRect(Image2.BoundsRect, ScreenToClient(Mouse.CursorPos)) then
    Image2MouseEnter(nil)
  else
    Image2MouseLeave(nil)

oh, and use constants for those rectangles.

 

TinyPortal © 2005-2018