You mentioned dragging of gadgets into position. It sounds like you are using a form designer. Which one are you using?
If you are not using a form designer the aspects that you need to consider when aligning the text involves two things. One is the border size of the control and the other is the font size.
Using the font's size you can determine the sizing of the controls so that text appears centered vertically by reducing the height to do so. You can do this by sizing the string control to the value returned by GadgetHeight(#gadgetNum, #PB_Gadget_RequiredSize) .
To align the text in TextBoxes and StringGadget requires accounting for whether each one has a border around it. One defaults to a border and the other defaults to borderless. The borders are 2 pixels in thickness (by appearance). So for a borderless TextBox and a StringGadget with a border you have to add 2 pixels to the vertical positioning of the TextBox.
Here's some sample code to demonstrate things. Set the constant #test =0 for the default font size and =1 for a larger Courier New 24 pt font.
Code: Select all
;Only tested on Windows
EnableExplicit
#test = 0 ;=0 for default font size, =1 for CourierNew 24pt size
Enumeration windows 1
#w_Record_set_up
EndEnumeration
Enumeration gadgets 1
#g_name_txt
#g_name_str
#g_officePhoneNo_txt
#g_officePhoneNo_str
#g_mobilePhoneNo_txt
#g_mobilePhoneNo_str
#g_Save_btn
#g_Cancel_btn
EndEnumeration
Enumeration images 1
#im_temp
EndEnumeration
Enumeration fonts 1
#f_Courier
EndEnumeration
Enumeration faultTypes
#ft_gadget_creation
#ft_window_creation
#ft_image_creation
#ft_image_drawing
#ft_map_element_creation
#ft_font_loading
#ft_generic
#ft_custom
EndEnumeration
;Handle Fault Types; prints text messsage if value <> 0 and ends program
Procedure HFT(value, type, text.s = "")
If Not value
Select type
Case #ft_gadget_creation
text = "Unable to create gadget."
Case #ft_window_creation
text = "Unable to create window."
Case #ft_image_creation
text = "Unable to create image."
Case #ft_image_drawing
text = "Unable to draw to image."
Case #ft_map_element_creation
text = "Unable to create map element."
Case #ft_font_loading
text = "Unable to load font."
Case #ft_custom
;use text as is.
Default
text = "Fatal error, unable to continue."
EndSelect
MessageRequester("Error", text.s)
End
EndIf
EndProcedure
Procedure window_Record_set_up()
CompilerIf #test = 0
Protected wx = 50, wy = 50, ww = 400, wh = 200
CompilerElse
Protected wx = 50, wy = 50, ww = 400 * 3, wh = 250 * 1.5
CompilerEndIf
Protected x, y, w, h, m = 50, sm = 30 ;m = margin and sm = spacing margin
Protected fid, borderAdj = 2 + 1
HFT(OpenWindow(#w_Record_set_up, wx, wy, ww, wh, "Record set-up", #PB_Window_SystemMenu), #ft_window_creation)
;For gadget font info only, this gadget will be setup properly later
HFT(StringGadget(#g_name_str, 0, 0, 0, 0, "XgpM"), #ft_gadget_creation)
CompilerIf #test = 0
fid = GetGadgetFont(#g_name_str) ;does not work with a default font on MAC OS
CompilerElse
HFT(LoadFont(#f_Courier, "Courier New", 24), #ft_font_loading)
fid = FontID(#f_Courier)
CompilerEndIf
SetGadgetFont(#g_name_str, fid)
;use height value for all gadgets with same font
h = GadgetHeight(#g_name_str, #PB_Gadget_RequiredSize)
w = (ww - (m * 2) - sm * 3) / 2: x = m: y = (m * 2 / 3) + borderAdj
HFT(TextGadget(#g_name_txt, x, y, w, h, "Name"), #ft_gadget_creation): y + (h * 1.75)
HFT(TextGadget(#g_officePhoneNo_txt, x, y, w, h, "Office Phone no."), #ft_gadget_creation): y + (h * 1.75)
HFT(TextGadget(#g_mobilePhoneNo_txt, x, y, w, h, "Mobile Phone no."), #ft_gadget_creation)
;size string gadgets to give matching space above and below text (results change in accordance with font sizes)
w = (ww - (m * 2) + sm) / 2: x = ww - m - w: y = (m * 2 / 3)
HFT(StringGadget(#g_name_str, x, y, w, h, "PBJim"), #ft_gadget_creation): y + (h * 1.75)
HFT(StringGadget(#g_officePhoneNo_str, x, y, w, h, "0234 1234 5678"), #ft_gadget_creation): y + (h * 1.75)
HFT(StringGadget(#g_mobilePhoneNo_str, x, y, w, h, "0780 9760 1023"), #ft_gadget_creation)
w = (ww - (m * 2) - (sm / 2) ) / 2: x = m: y + (h * 2.25)
HFT(ButtonGadget(#g_Save_btn, x, y, w, h, "Save"), #ft_gadget_creation)
x = ww - m - w
HFT(ButtonGadget(#g_Cancel_btn, x, y, w, h, "Cancel"), #ft_gadget_creation)
;uncomment the following two lines to see the actual text areas
;SetGadgetColor(#g_name_txt, #PB_Gadget_BackColor, RGB(0, 255, 0))
;SetGadgetColor(#g_name_str, #PB_Gadget_BackColor, RGB(255, 255, 0))
SetGadgetFont(#g_name_txt, fid)
SetGadgetFont(#g_name_str, fid)
SetGadgetFont(#g_officePhoneNo_str, fid)
SetGadgetFont(#g_officePhoneNo_txt, fid)
SetGadgetFont(#g_mobilePhoneNo_str, fid)
SetGadgetFont(#g_mobilePhoneNo_txt, fid)
SetGadgetFont(#g_Save_btn, fid)
SetGadgetFont(#g_Cancel_btn, fid)
EndProcedure
window_Record_set_up()
Define event, quit = #False
Repeat
event = WaitWindowEvent()
Select event
Case #PB_Event_CloseWindow
quit = #True
Case #PB_Event_Gadget
Select EventGadget()
Case #g_name_str
Case #g_officePhoneNo_str
Case #g_mobilePhoneNo_str
Case #g_Save_btn
;save values as record
quit = #True
Case #g_Cancel_btn
quit = #True
EndSelect
EndSelect
Until quit = #True