如何在dm脚本中创建一个旋转框?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在dm脚本中创建一个旋转框?相关的知识,希望对你有一定的参考价值。
我想在dm-script中的模态/无模式对话框上创建一个旋转框,它允许用户通过单击向上或向下箭头按钮(即旋转按钮)来增加或减少文本字段中的数值。
有没有合适的方法来创建这样的旋转盒?如果你分享一些智慧,将不胜感激。非常感谢你提前。
答案
There exists no "spin control" for scripted dialogs.
但是,您可以通过创建和排列按钮来构建代理旋转控件。它有点粗糙,但以下代码创建了这个:
Class CMySpin : UIFrame
{
TagGroup CreateDLGTgs( object self )
{
TagGroup DLGtgs, DLGItems
DLGtgs = DLGCreateDialog( "Test", DLGItems )
TagGroup upButton = DLGCreatePushButton( "U", "OnPushUp" ).DLGExternalPadding(0,-5).DLGInternalPadding(-2,-3)
TagGroup downButton = DLGCreatePushButton( "D", "OnPushDown" ).DLGInternalPadding(-2,-3)
TagGroup field = DLGCreateIntegerField( 10, 10 ).DLGIdentifier( "field" )
TagGroup SpinGroup = DLGGroupItems( upButton, downButton ).DLGTableLayout(1,2,0)
TagGroup fieldWithSpin = DLGGroupItems( field, SpinGroup ).DLGTableLayout(2,1,0)
DLGItems.DLGAddElement( fieldWithSpin )
return DLGtgs
}
void OnPushUp( object self )
{
taggroup fieldTG = self.LookupElement( "field" )
number value = fieldTG.DLGGetValue()
value++
fieldTG.DLGValue( value )
}
void OnPushDown( object self )
{
taggroup fieldTG = self.LookupElement( "field" )
number value = fieldTG.DLGGetValue()
value--
fieldTG.DLGValue( value )
}
void CreateAndPose( object self )
{
self.Init( self.CreateDLGTgs() )
self.Pose()
}
}
Alloc(CMySpin).CreateAndPose()
然后,您可以使用位图按钮而不是简单的按钮来设置外观,直到它们看起来更具吸引力。
F.E.我创建了这个变种:
使用此代码:
Class CMySpin : UIFrame
{
TagGroup CreateDLGTgs( object self )
{
image arrowImg := [7,5]:
{ { 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 1, 0, 0, 0 },
{ 0, 0, 1, 1, 1, 0, 0 },
{ 0, 1, 1, 1, 1, 1, 0 },
{ 0, 0, 0, 0, 0, 0, 0 } }
number factor = 2
image upArrow := RealImage("",4,factor*7,factor*5)
upArrow=arrowImg.warp( icol / factor, irow / factor )
image downArrow = upArrow
downArrow.FlipVertical()
rgbImage upArrowUp = RGB( upArrow * 100, upArrow * 100, upArrow * 100 )
rgbImage upArrowDown = RGB( upArrow * 200, upArrow * 200, upArrow * 200 )
rgbImage downArrowUp = RGB( downArrow * 100, downArrow * 100, downArrow * 100 )
rgbImage downArrowDown = RGB( downArrow * 200, downArrow * 200, downArrow * 200 )
TagGroup DLGtgs, DLGItems
DLGtgs = DLGCreateDialog( "Test", DLGItems )
TagGroup upButton = DLGCreateBevelButton( upArrowUp, upArrowDown, "OnPushUp" ).DLGExternalPadding(0,-3).DLGInternalPadding(-2,-3)
TagGroup downButton = DLGCreateBevelButton( downArrowUp, downArrowDown, "OnPushDown" ).DLGExternalPadding(0,-3).DLGInternalPadding(-2,-3)
TagGroup field = DLGCreateIntegerField( 10, 10 ).DLGIdentifier( "field" )
TagGroup SpinGroup = DLGGroupItems( upButton, downButton ).DLGTableLayout(1,2,0)
TagGroup fieldWithSpin = DLGGroupItems( field, SpinGroup ).DLGTableLayout(2,1,0)
DLGItems.DLGAddElement( fieldWithSpin )
return DLGtgs
}
void OnPushUp( object self )
{
taggroup fieldTG = self.LookupElement( "field" )
number value = fieldTG.DLGGetValue()
value++
fieldTG.DLGValue( value )
}
void OnPushDown( object self )
{
taggroup fieldTG = self.LookupElement( "field" )
number value = fieldTG.DLGGetValue()
value--
fieldTG.DLGValue( value )
}
void CreateAndPose( object self )
{
self.Init( self.CreateDLGTgs() )
self.Pose()
}
}
Alloc(CMySpin).CreateAndPose()
以上是关于如何在dm脚本中创建一个旋转框?的主要内容,如果未能解决你的问题,请参考以下文章