Button Design In PowerBuilder
Source Code
uo_dwbutton from datawindow
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | forward global type uo_dwbutton from datawindow end type end forward global type uo_dwbutton from datawindow integer width = 686 integer height = 400 string title = "none" boolean livescroll = true borderstyle borderstyle = stylelowered! event mousemove pbm_mousemove event mousedown pbm_lbuttondown event mouseup pbm_lbuttonup end type global uo_dwbutton uo_dwbutton type prototypes Function Long SetCapture( Long hwnd) Library "user32" Function Long ReleaseCapture() Library "user32" Function ULong CreateRoundRectRgn(ULong X1,ULong Y1,ULong X2,ULong Y2,ULong X3,ULong Y3) Library "gdi32.dll" Function ULong SetWindowRgn(ULong hwnd,ULong hRgn,Boolean bRedraw) Library "user32.dll" end prototypes type variables Boolean changed = False Long w1,h1 //The width and height of the button, in pixels String is_ButtonText = "None" //Button name Long il_TextSize = -10 String is_TextFont = "Arial" Long il_TextColor = 16777215 Long il_HoverTextColor = 16711680 Int ii_BlueS = 255 Int ii_GreenS = 255 Int ii_RedS = 255 Int ii_BlueE = 0 Int ii_GreenE = 0 Int ii_RedE = 0 end variables forward prototypes public subroutine of_setbuttontext (string as_text) public subroutine of_settextsize (long al_textsize) public subroutine of_settextfont (string as_textfont) public subroutine of_settextcolor (long al_textcolor) public subroutine of_sethovertextcolor (long al_hovertextcolor) public subroutine of_setbackgroundendcolor (long al_color) public subroutine of_setbackgroundstartcolor (long al_color) end prototypes event mousemove;Long hand hand = Handle(This) //Forms a gradient of white and black below If xpos >= 0 And xpos <= This.Width And ypos >= 0 And ypos <= This.Height Then If Not changed Then Integer i_for Long j_1 String s_name,s_create For i_for = 0 To h1 s_name = "line_"+String(i_for) j_1 = RGB((h1 - (i_for + ii_RedE))*ii_RedS/h1,(h1 - (i_for + ii_GreenE))*ii_GreenS/h1,(h1 - (i_for + ii_BlueE))*ii_BlueS/h1) s_create = s_name+".pen.color='"+String(j_1)+"'" This.Modify(s_create) Next This.Modify("psp.color='"+String(il_HoverTextColor)+"'") End If changed = True SetCapture(hand) Else This.TriggerEvent("mouseup") changed = False ReleaseCapture() End If end event event mouseup;Integer i_for Long j_1 String s_name,s_create //Forms a gradient of black and white For i_for = 0 To h1 s_name = "line_"+String(i_for) j_1 = RGB((i_for + ii_RedE) *ii_RedS/h1,(i_for + ii_GreenE) *ii_GreenS/h1,(i_for + ii_BlueE) *ii_BlueS/h1) s_create = s_name+".pen.color='"+String(j_1)+"'" This.Modify(s_create) Next This.Modify("psp.color='"+String(il_TextColor)+"'") changed = False end event public subroutine of_setbuttontext (string as_text);is_ButtonText = as_Text This.Event Constructor( ) end subroutine public subroutine of_settextsize (long al_textsize);il_TextSize = al_TextSize This.Event Constructor( ) end subroutine public subroutine of_settextfont (string as_textfont);is_TextFont = as_TextFont This.Event Constructor( ) end subroutine public subroutine of_settextcolor (long al_textcolor);il_TextColor = al_TextColor This.Event Constructor( ) end subroutine public subroutine of_sethovertextcolor (long al_hovertextcolor);il_HoverTextColor = al_HoverTextColor This.Event Constructor( ) end subroutine public subroutine of_setbackgroundendcolor (long al_color);Long ll_rgb ll_rgb = al_color ii_BlueE = Int(ll_rgb/65536.0) ll_rgb -= ii_BlueE*Long(65536) ii_GreenE = Int(ll_rgb/256.0) ii_RedE = ll_rgb - ii_GreenE*256 This.Event Constructor( ) end subroutine public subroutine of_setbackgroundstartcolor (long al_color);Long ll_rgb ll_rgb = al_color ii_BlueS = Int(ll_rgb/65536.0) ll_rgb -= ii_BlueS*Long(65536) ii_GreenS = Int(ll_rgb/256.0) ii_RedS = ll_rgb - ii_GreenS*256 This.Event Constructor( ) end subroutine on uo_dwbutton.create end on on uo_dwbutton.destroy end on event constructor;// button shape String ls_err Integer i_for Long j_1 String ls_name,ls_create //w1 = UnitsToPixels(This.Width,XUnitsToPixels!) //h1 = UnitsToPixels(This.Height,yUnitsToPixels!) w1 = This.Width - 1 h1 = This.Height - 1 This.Create('release 10.5; datawindow() table(column=(type=number name=dummy dbname="dummy" ))', ls_err) If Len(ls_err) > 0 Then MessageBox("DW Create Error", ls_err) End If //Forms a gradient of black and white For i_for = 0 To h1 ls_name = "line_"+String(i_for) //j_1 = RGB(i_for*255/h1,i_for*255/h1,i_for*255/h1) j_1 = RGB((i_for + ii_RedE) *ii_RedS/h1,(i_for + ii_GreenE )*ii_GreenS/h1,(i_for + ii_BlueE)*ii_BlueS/h1) ls_create = "create line(band=background x1='0'" ls_create = ls_create+" y1='"+String(i_for)+"' x2='"+String(w1)+"'" ls_create = ls_create+" y2='"+String(i_for)+"' name=line_"+String(i_for)+ " pen.color='"+String(j_1)+"' pen.width='1') " This.Modify(ls_create) Next ls_create = "create text(band=background alignment='0' text=' "+is_ButtonText+"' border='0' color='"+String(il_TextColor)+"' name=psp x='0' y='0' height='"+String(h1)+"' width='"+String(w1)+"' font.face='"+is_TextFont+"' font.height='"+String(il_TextSize)+"' font.weight='400' font.family='2' font.pitch='2' font.charset='0' background.mode='1' background.color='553648127')" This.Modify(ls_create) end event |
uo_picbutton from picture
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | forward global type uo_picbutton from picture end type end forward global type uo_picbutton from picture integer width = 329 integer height = 176 boolean originalsize = true boolean focusrectangle = false event mousedown pbm_lbuttondown event mousemove pbm_mousemove event mouseup pbm_lbuttonup end type global uo_picbutton uo_picbutton type prototypes Function Long SetCapture( Long hwnd) Library "user32" Function Long ReleaseCapture() Library "user32" Function ulong CreateRoundRectRgn(ulong X1,ulong Y1,ulong X2,ulong Y2,ulong X3,ulong Y3) LIBRARY "gdi32.dll" Function ulong SetWindowRgn(ulong hWnd,ulong hRgn,boolean bRedraw) LIBRARY "user32.dll" end prototypes type variables Boolean changed = False String s_normal //image path and file name in normal state String s_over //The image path and file name under the mouse over String s_down //The image path and file name under the mouse button String s_disable //The image path and file name in the disabled state String s_info //The prompt information of the mouse over end variables event mousedown;This.PictureName = s_down end event event mousemove;Long hand hand = Handle(This) If xpos >= 0 And xpos <= This.Width And ypos >= 0 And ypos <= This.Height Then If Not changed Then This.PictureName = s_over changed = True End If SetCapture(hand) Else This.PictureName = s_normal changed = False ReleaseCapture() End If end event event mouseup;This.PictureName = s_normal changed = False end event on uo_picbutton.create end on on uo_picbutton.destroy end on event constructor;//This button is a rounded button //The script here is the same as above, omitted here to save space This.Border = False This.PictureName = s_normal end event |
uo_textbutton from statictext
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | forward global type uo_textbutton from statictext end type end forward global type uo_textbutton from statictext integer width = 402 integer height = 64 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" long textcolor = 33554432 long backcolor = 67108864 string text = "none" boolean focusrectangle = false event mousedown pbm_lbuttondown event mouseup pbm_lbuttonup event mousemove pbm_mousemove end type global uo_textbutton uo_textbutton type prototypes Function Long SetCapture( Long hwnd) Library "user32" Function Long ReleaseCapture() Library "user32" Function ulong CreateRoundRectRgn(ulong X1,ulong Y1,ulong X2,ulong Y2,ulong X3,ulong Y3) LIBRARY "gdi32.dll" Function ulong SetWindowRgn(ulong hWnd,ulong hRgn,boolean bRedraw) LIBRARY "user32.dll" end prototypes type variables boolean changed=false end variables event mousedown;// button display sag This.BorderStyle = StyleLowered! end event event mouseup;//button back to normal This.Weight = 400 This.TextColor = RGB(0,64,128) This.BorderStyle = StyleRaised! changed = False ReleaseCapture() end event event mousemove;Long hand hand = Handle(This) If xpos >= 0 And xpos <= This.Width And ypos >= 0 And ypos <= This.Height Then If Not changed Then //The button text turns red and thicker when the mouse is moved //You can also change the background color, there is no change here This.Weight = 700 This.TextColor = RGB(255,0,0) changed = True End If SetCapture(hand) Else //The button text returns to its original state when the mouse moves out of the button This.Weight = 400 This.TextColor = RGB(0,64,128) This.BorderStyle = StyleRaised! changed = False ReleaseCapture() End If end event on uo_textbutton.create end on on uo_textbutton.destroy end on event constructor;Long l1 Long x1,y1,w1,h1 x1 = UnitsToPixels(This.X,XUnitsToPixels!) y1 = UnitsToPixels(This.Y,yUnitsToPixels!) w1 = UnitsToPixels(This.Width,XUnitsToPixels!) h1 = UnitsToPixels(This.Height,yUnitsToPixels!) l1 = CreateRoundRectRgn(1,1,w1,h1,4,4) setwindowRgn(Handle(This),l1,True) end event |
Window Example
w_main from window
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | forward global type w_main from window end type type p_min from uo_picbutton within w_main end type type p_max from uo_picbutton within w_main end type type dw_1 from uo_dwbutton within w_main end type type p_uclose from uo_picbutton within w_main end type type st_1 from uo_textbutton within w_main end type end forward global type w_main from window integer width = 2354 integer height = 888 boolean titlebar = true string title = "Button Design" boolean controlmenu = true boolean minbox = true boolean maxbox = true boolean resizable = true long backcolor = 67108864 string icon = "AppIcon!" boolean center = true p_min p_min p_max p_max dw_1 dw_1 p_uclose p_uclose st_1 st_1 end type global w_main w_main on w_main.create this.p_min=create p_min this.p_max=create p_max this.dw_1=create dw_1 this.p_uclose=create p_uclose this.st_1=create st_1 this.Control[]={this.p_min,& this.p_max,& this.dw_1,& this.p_uclose,& this.st_1} end on on w_main.destroy destroy(this.p_min) destroy(this.p_max) destroy(this.dw_1) destroy(this.p_uclose) destroy(this.st_1) end on event open;p_uclose.s_normal = "Exit1.bmp" p_uclose.s_over = "Exit5.bmp" p_uclose.s_down = "Exit3.bmp" p_uclose.s_disable = "Exit4.bmp" p_uclose.TriggerEvent(Constructor!) p_max.s_normal = "Max1.bmp" p_max.s_over = "Max5.bmp" p_max.s_down = "Max3.bmp" p_max.s_disable = "Max4.bmp" p_max.TriggerEvent(Constructor!) p_min.s_normal = "Min1.bmp" p_min.s_over = "Min5.bmp" p_min.s_down = "Min3.bmp" p_min.s_disable = "Min4.bmp" p_min.TriggerEvent(Constructor!) dw_1.of_setbuttontext("https://pblib.com/") dw_1.of_settextsize( -20) dw_1.of_setbackgroundstartcolor(255) end event type p_min from uo_picbutton within w_main integer x = 1207 integer y = 32 integer width = 293 integer height = 224 boolean originalsize = false end type type p_max from uo_picbutton within w_main integer x = 1573 integer y = 32 integer width = 293 integer height = 224 boolean originalsize = false end type type dw_1 from uo_dwbutton within w_main integer x = 37 integer y = 480 integer width = 2231 integer height = 256 integer taborder = 10 long w1 = 951 long h1 = 300 end type type p_uclose from uo_picbutton within w_main integer x = 1938 integer y = 32 integer width = 293 integer height = 224 boolean originalsize = false end type type st_1 from uo_textbutton within w_main integer x = 73 integer y = 320 integer width = 1801 integer height = 128 integer textsize = -16 string text = "https://pblib.com/" end type |
Find Projects On Github click here
Good Luck!