如何获得dw内text控件自动调整后的高度?
dw中的text控件是atuosize height的,怎么获得它调整后的高度,我想根据此高度来设置window中dw的高度
[解决办法]
这问题确实是pb中无法解决的一个问题,我也被困扰了很久一直没解决,通过自己的尝试与上网的了解总共得出3中方案,我都没试过,第1种是我自己想的,但是很难做;第2种是前版主的办法;第3种不知道是怎么做的我也没研究,太长了
1、用api函数EnumChildWindows找到那个自动高度的text的handle,但是这个api函数在pb里似乎很难直接调用,需要用vc写个接口才行,我这么想。
2、我想可以用Wm_GetFont/CreateFontIndirect + GetTextExtentpoint32获取每个字符的宽度、高度,用DW_1.Object.Column.Width除以每个字符的宽度,即可获取每行显示多少个字符,然后用总的字符个数(这个通过GETITEMSTRING()不难获取)再除以每行的字符个数,即得总行数,然后总行数乘以每个字符的高度即得总高度;
此外总行数也可以通过.LineCount ( )、.Position ( )、.SelectedLine ( )等函数获取;
3、在现在的PB version 中没有这个功能,只能人为去改变,下面是我做过的一个程序,测试没有问题不全一样但是可以实现你的需求。
////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Event: ue_dysetheight
// Description: user base the relatively column of value to dynamic set the current column of height,
// 1>if current height is 0 then set current height is is_columnheight(set in the ini file)
// 2>if current height is more than is_columnheight then get the difference (the current
// height - is_columnheight). the below text and column move the pos is the difference.
// at the same menmont set the current column of height of value
// 3>set detail band of height.
//
// Arguments: none
//
// Returns: integer
// 1 success
// -1 failed
//
////////////////////////////////////////////////////////////////////////////////////////////////////////
// Revision History
// Version Who Date Desc
// 1.0 Alan Li 20021212 Initial Version
////////////////////////////////////////////////////////////////////////////////////////////////////////
long ll_dwloop //the datawindow of circle var
long ll_loop
long ll_cloop //need change y pos of column and text
long ll_columnheight //columnheight
long ll_textheight //textheight
long ll_difheight //need change y pos
long ll_columncount //column count
long ll_detailheight //detail band height
long ll_modiloop
string ls_height //set relative column of height
string ls_columntext //set y pos of clolumn of text
string ls_columnname //set y pos of clolumn of name
string ls_return
string ls_editmask //editmask
string ls_coltype
string ls_tmpname //conv columnname
string ls_modistr //modify of string
any la_value //set all type of value to the var
dec{4} lf_convalue //conv decimal value
string ls_convalue //conv string value
boolean lb_noscroll=false //no use set vscroll
boolean lb_error=false
boolean lb_modi = false
is_modichangecolor = string(RGB(il_modichangered,il_modichangegreen,il_modichangeblue)) //modify background color string
ll_textheight=long(is_textheight)
for ll_dwloop= il_oritabcount + 1 to upperbound(idw_dw[])
idw_dw[ll_dwloop].setredraw(false)
ll_difheight=0 //repeate set value
ll_columnheight=0 //repeate set value
ll_detailheight=0 //repeate set value
ll_columncount=long(idw_dw[ll_dwloop].Describe('DataWindow.Column.Count')) //get the current template column count
for ll_loop=1 to ll_columncount
lb_noscroll = false
ls_columnname=idw_dw[ll_dwloop].describe('#'+string(ll_loop)+'.Name') //get column name
ls_coltype=idw_dw[ll_dwloop].describe('#'+string(ll_loop)+'.coltype') //get column type
ls_columntext=ls_columnname+'_t'
la_value = idw_dw[ll_dwloop].object.data[1,ll_loop] //get value
//-------------------------------------------------------------------------
lb_modi = false //repeate set value
//set already modify backcolor
for ll_modiloop = 1 to upperbound(is_modichangefield)
if upper(trim(ls_columnname)) = is_modichangefield[ll_modiloop] then
lb_modi = true
exit
end if
next
if lb_modi = true then
ls_modistr = "#"+string(ll_loop)+".background.color='"+is_modichangecolor+"'"
ls_return = idw_dw[ll_dwloop].modify(ls_modistr)
if len(ls_return) > 0 then
lb_error=true
exit
end if
end if
//-------------------------------------------------------------------------
//get the current column should was setted column height
ll_columnheight=(ceiling(len(trim(string(la_value)))/long(is_Columncharactercount)))*long(is_columnheight)
if isnull(ll_columnheight) or ll_columnheight=0 or ll_columnheight <= long(is_columnheight) then
ll_columnheight=long(is_columnheight)
lb_noscroll = true
end if
//get the below column and text should move y pos of count.
ll_difheight=ll_difheight+ll_columnheight -long(is_columnheight)
ls_return=idw_dw[ll_dwloop].modify(ls_columnname + ".height ='" + &
string(ll_columnheight)+"'") //set column of height
if len(ls_return) > 0 then
lb_error=true
exit
end if
//if the column of value is too much set the column set vscroll bar
if lb_noscroll = true then
ls_return=idw_dw[ll_dwloop].modify(ls_columnname + ".Edit.VScrollBar =no") //set column of height
if len(ls_return) > 0 then
lb_error=true
exit
end if
elseif lb_noscroll = false then
ls_return=idw_dw[ll_dwloop].modify(ls_columnname + ".Edit.VScrollBar =yes") //set column of height
if len(ls_return) > 0 then
lb_error=true
exit
end if
end if
//----------------------------------------------------
//change the datavalue show format,if edit format is editmask or dddw and so on.
//----------------------------------------------------
//form other edit mask to edit format
idw_dw[ll_dwloop].modify("#"+string(ll_loop)+".edit.case='any'")
idw_dw[ll_dwloop].modify("#"+string(ll_loop)+".edit.AutoSelect='Yes'")
idw_dw[ll_dwloop].modify("#"+string(ll_loop)+".edit.DisplayOnly='yes'")
ls_editmask=''
ls_tmpname=upper(ls_columnname)
select mask into :ls_editmask
from template_field
where field_name=:ls_tmpname and source_name=:is_sourcename using itr_tran;
if itr_tran.sqlcode <> 0 then
lb_error = true
exit
end if
if not(isnull(ls_editmask) or ls_editmask ='') then
em_convalue.setfocus()
em_convalue.SetMask(StringMask!,ls_editmask )
em_convalue.text=trim(string(la_value))
ls_convalue = trim(em_convalue.textline())
//according the data type into relative data.
if left(upper(ls_coltype),7) = 'DECIMAL' then
lf_convalue=long((ls_convalue))
idw_dw[ll_dwloop].object.data[1,ll_loop] = lf_convalue
else
idw_dw[ll_dwloop].object.data[1,ll_loop] = ls_convalue
end if
end if
//----------------------------------------------------