1. kevin kevin rowe
  2. PowerBuilder
  3. Friday, 13 May 2022 12:37 PM UTC

I need to extend a picture button so that I can control where the text is placed in the button better.

I also want to make the button have a 'hover' image like a web button.

This has proven challenging, but I've made a sample user object below that can be dropped on a window and tested.

Is there a way to effectively control the Z order of controls on a form? I can't see any method except 'send to back' in the IDE.

Also, is there any documentation I can scan for implementing a mousedown event?

 

[code]

forward
global type uuo_favbut from userobject
end type
type st_legend from statictext within uuo_favbut
end type
type pbackground from picture within uuo_favbut
end type
type pbackgroundhover from picture within uuo_favbut
end type
end forward

global type uuo_favbut from userobject
integer width = 361
integer height = 320
long backcolor = 553648127
string text = "none"
long tabtextcolor = 33554432
long picturemaskcolor = 536870912
st_legend st_legend
pbackground pbackground
pbackgroundhover pbackgroundhover
end type
global uuo_favbut uuo_favbut

forward prototypes
public subroutine of_setbackground (string asfilename)
public subroutine of_sethoverbackground (string asfilename)
public subroutine of_settext (string astext)
public subroutine of_setfontsize (integer aisize)
end prototypes

public subroutine of_setbackground (string asfilename);pBackground.picturename = asfilename
end subroutine

public subroutine of_sethoverbackground (string asfilename);pBackgroundHover.picturename = asfilename
end subroutine

public subroutine of_settext (string astext);st_legend.text = astext
end subroutine

public subroutine of_setfontsize (integer aisize);st_legend.textsize = aiSize
end subroutine

on uuo_favbut.create
this.st_legend=create st_legend
this.pbackground=create pbackground
this.pbackgroundhover=create pbackgroundhover
this.Control[]={this.st_legend,&
this.pbackground,&
this.pbackgroundhover}
end on

on uuo_favbut.destroy
destroy(this.st_legend)
destroy(this.pbackground)
destroy(this.pbackgroundhover)
end on

type st_legend from statictext within uuo_favbut
integer x = 37
integer y = 28
integer width = 288
integer height = 260
boolean bringtotop = true
integer textsize = -10
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
long textcolor = 33554432
long backcolor = 553648127
string text = "none"
alignment alignment = center!
boolean focusrectangle = false
end type

event clicked;setredraw(false)
pBackground.visible = false
pbackgroundhover.visible = true
st_legend.visible = true
setredraw(true)

sleep (1)
setredraw(false)
pBackground.visible = true
pbackgroundhover.visible = false
st_legend.visible = true
setredraw(true)

Message.StringParm = this.Tag
Parent.PostEvent ("ue_fav_clicked")
end event

type pbackground from picture within uuo_favbut
integer width = 361
integer height = 320
string picturename = "Custom080!"
boolean focusrectangle = false
end type

event clicked;setredraw(false)
pBackground.visible = false
pbackgroundhover.visible = true
st_legend.visible = true
setredraw(true)

sleep (1)
setredraw(false)
pBackground.visible = true
pbackgroundhover.visible = false
st_legend.visible = true
setredraw(true)

Message.StringParm = this.Tag
Parent.PostEvent ("ue_fav_clicked")
end event

type pbackgroundhover from picture within uuo_favbut
boolean visible = false
integer width = 361
integer height = 320
string picturename = "Custom080a!"
boolean focusrectangle = false
end type

[/code]

Accepted Answer
John Fauss Accepted Answer Pending Moderation
  1. Friday, 13 May 2022 14:37 PM UTC
  2. PowerBuilder
  3. # Permalink

Hi, Kevin -

Windows and window controls have a BringToTop property. Look at the Help topic for BringToTop, as there are some limitations on its use.

In regards to your "mousedown" question; Many/most events in PB are reflections of Windows events, and there is no MouseDown event or WM_MOUSEDOWN event message that Windows issues across all controls. There are, however, WM_LBUTTONDOWN, WM_LBUTTONUP, WM_RBUTTONDOWN, and WM_RBUTTONUP Windows event messages - PB may not always supply a PB implementation of these events across all controls, but you can usually add PB user events to a control that are mapped to the PB equivalents to the Windows event messages: pbm_lbuttondown, pbm_lbuttonup, pbm_rbuttondown & pbm_lbuttonup.  The Right-mouse button event messages used in DataWindows are named differently: pbm_dwnrbuttondown, & pbm_dwnrbuttonup. A little confusing, I know.

Windows (and PB) can also utilize "non-client" versions of the left/right mouse button down/up event messages. In PB, these would be user events mapped to pbm_nclbuttondown/up and pbmncrbuttondown/up.

As for documentation, I go to the source, which is Windows. The Windows API documentation is pretty good. I keep a bookmark in my browser to it:

   https://docs.microsoft.com/en-us/windows/win32/apiindex/windows-api-list

If you want information about a particular message, search within the Windows API documentation for the Windows event message code. For example, for the LButtonDown message, search for WM_LBUTTONDOWN (the "WM" stands for "Windows Message"):

   https://docs.microsoft.com/en-us/windows/win32/inputdev/wm-lbuttondown

Of course, the Windows API documentation will not include any information on DataWindow-related messages - but in many (but not all) cases, DW events are reflections of Windows events.

I hope this helps you along. Good luck with your project!

Comment
  1. Chris Pollach @Appeon
  2. Friday, 13 May 2022 15:59 PM UTC
In addition to John's great answer .. the DataWindow has a further "Z" axis control feature. Not only does it have a Bring Forward, Send Back feature - you can also do this in the Foreground, Band and Background layers (front/back) giving you further Z-Axis control.Also, the DWO handles transparencies must better as well. FWIW: I try and only use DWO's for all my controls as A) they have more features, B) Easier to design & code, C) Take far less MS-Windows over head and D) are Zoomable too! Food for thought. ;-)
  1. Helpful
There are no comments made yet.
Andreas Mykonios Accepted Answer Pending Moderation
  1. Friday, 13 May 2022 13:54 PM UTC
  2. PowerBuilder
  3. # 1

It would be easier if you exported your userobject as an sru.

Z index isn't available as a property. You do have a BringToTop for windows and controls. So you can write something like that:

<your_control1>.bringtotop = false
<your_control2>.bringtotop = true

Of course your controls should overlap to see that.

Lets say that cb_1 overlaps with cb_2 and cb_1 is in front of cb_2. Following code will bring cb_2 in front:

cb_2.bringtotop = true

But running the following instead of previous one will have the same effect:

cb_1.bringtotop = false

If you have to many overlapping controls, then you should probably handle that situation using control[] array in your window (or your userobject). You should execute bringtotop = true in serial mode, first on the object that should be in the back and last for the object that should be in the front. You can do the same in reverse mode using bringtotop = false.

Andreas.

Comment
  1. kevin kevin rowe
  2. Friday, 13 May 2022 15:11 PM UTC
Andreas is right in that the serial bring to top seems to be necessary to make the image show. This is just a workaround, mind. What I actually want to do is implement the handler for LButtonDown message as per john's answer.
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.