| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2308 人关注过本帖
标题:这个方法错在呢?
取消只看楼主 加入收藏
不懂才问
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:大草原
等 级:贵宾
威 望:29
帖 子:1503
专家分:6593
注 册:2010-7-5
结帖率:91.53%
收藏
已结贴  问题点数:100 回复次数:4 
这个方法错在呢?
CLEAR ALL
CLOSE PROCEDURES
SET PROCEDURE TO "MyFormClass", "MyLoginForm"&&,"otherForm"
runShouliaoForm()

CLOSE PROCEDURES
&&CLOSE ALL
return

PROCEDURE runShouliaoForm
    PUBLIC  shouliaoForm
    shouliaoForm=CREATEOBJECT("m1Form")   
    shouliaoForm.show
    READ EVENTS
    RETURN
ENDPROC

DEFINE CLASS m1Form as myForm
    showWindow=2
    caption="功能1——收料单"
    autoCenter=.t.
    windowType=1
    beforeWidth=this.width
    currWidth=this.width
    beforeHeight=this.Height
    currHeight=this.Height
    minWidth=this.Width
    minHeight=this.Height
    rowStep=1
    colStep=1
    formHeightZoom=1
    formWidthZoom=1
   
   
    ADD OBJECT titleLabel1 as label WITH caption="收 料 单",backColor=RGB(222,222,222)

    PROCEDURE Arrange
        LOCAL tempFormWidth,tempFormHeight
        tempFormWidth=this.width
        tempFormHeight=this.height
        IF (this.beforeWidth<>tempFormWidth) .or. (this.beforeHeight<>tempFormHeight)
            this.currWidth=tempFormWidth
            this.currHeight=tempFormHeight
            this.formHeightZoom=thisform.currHeight/thisform.minHeight
            this.formWidthZoom=thisform.currWidth/thisform.minWidth
        ENDIF
        WITH this.titleLabel1
            .top=24*this.formHeightZoom
            .left=(this.width-.width)/2
            .width=127*this.formWidthZoom
            .height=29*this.formHeightZoom
            .fontSize=thisform.fontReSize(.height,.width,.class,18)
        ENDWITH

        this.beforeWidth=this.width
        this.beforeHeight=this.height
        thisform.refresh
    ENDPROC
   
    PROCEDURE Activate
        This.Arrange
    ENDPROC
   
    PROCEDURE Resize
        This.Arrange
    ENDPROC
   
    PROCEDURE fontReSize
        PARAMETERS nHeight,nWidth,nBaseClass,nBaseFontSize
        thisform.addobject('testControl',nBaseClass)
            WITH thisform.testControl
                autoSize=.t.
                LOCAL tempFontSize
                FOR tempFontSize=8 TO 72
                    thisform.testControl.fontSize=tempFontSize
                    IF (thisform.testControl.height>nHeight) .or. (thisform.testControl.width>nWidth)
                        thisform.testControl.fontSize=tempFontSize-0.5
                    ENDIF
                ENDFOR
            ENDWITH
        IF thisform.testControl.fontSize<=nBaseFontSize         
            RETURN nBaseFontSize
        ELSE
            RETURN thisform.testControl.fontSize
        ENDIF
        thisform.testControl.release
    ENDPROC

      
    PROCEDURE Destroy
        CLEAR EVENTS
    ENDPROC
   
ENDDEFINE

红字部分  是我想实现的方法  但是   总是有同名成员对象存在   什么情况呢?

我想这个方法实现的功能  就是把控件的宽、高、类、最低字号传进来
当窗体放大或者缩小的时候,再建一个同样的控件   进行字号对比   最后返回最适合的字号
对比完成  释放这个临时的控件
。。。  请各位老师指导一下   谢谢   迷糊了    
搜索更多相关主题的帖子: PUBLIC 
2015-12-23 13:26
不懂才问
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:大草原
等 级:贵宾
威 望:29
帖 子:1503
专家分:6593
注 册:2010-7-5
收藏
得分:0 
完全的乱了   。。。

CLEAR ALL
CLOSE PROCEDURES
SET PROCEDURE TO "MyFormClass", "MyLoginForm"&&,"otherForm"
runShouliaoForm()

CLOSE PROCEDURES
&&CLOSE ALL
return

PROCEDURE runShouliaoForm
    PUBLIC  shouliaoForm
    shouliaoForm=CREATEOBJECT("m1Form")   
    shouliaoForm.show
    READ EVENTS
    RETURN
ENDPROC

DEFINE CLASS m1Form as myForm
    showWindow=2
    caption="功能1——收料单"
    autoCenter=.t.
    windowType=1
    beforeWidth=this.width
    currWidth=this.width
    beforeHeight=this.Height
    currHeight=this.Height
    minWidth=this.Width
    minHeight=this.Height
    rowStep=1
    colStep=1
    formHeightZoom=1
    formWidthZoom=1
   
    &&用作参照物的控件
    ADD OBJECT referLabel as label &&WITH visible=.f.
   
    ADD OBJECT titleLabel1 as label WITH caption="收 料 单",backColor=RGB(222,222,222)

    PROCEDURE Arrange
        WITH this.titleLabel1
            .top=24*this.formHeightZoom
            .left=(this.width-.width)/2
            .width=127*this.formWidthZoom
            .height=29*this.formHeightZoom
            .fontSize=18
        ENDWITH
        LOCAL tempFormWidth,tempFormHeight
        tempFormWidth=this.width
        tempFormHeight=this.height
        IF (this.beforeWidth<>tempFormWidth) .or. (this.beforeHeight<>tempFormHeight)
            this.currWidth=tempFormWidth
            this.currHeight=tempFormHeight
            this.formHeightZoom=thisform.currHeight/thisform.minHeight
            this.formWidthZoom=thisform.currWidth/thisform.minWidth
            
            thisform.titleLabel1.FontSize=thisform.fontReSize(thisform.titleLabel1.height,thisform.titleLabel1.width,thisform.titleLabel1.FontSize,1)
            
        ENDIF

        this.beforeWidth=this.width
        this.beforeHeight=this.height
        thisform.refresh
    ENDPROC
   
    PROCEDURE Activate
        This.Arrange
    ENDPROC
   
    PROCEDURE Resize
        This.Arrange
    ENDPROC
   
    PROCEDURE fontReSize
        PARAMETERS nHeight,nWidth,nBaseFontSize,nBaseClass
        IF nBaseClass=1      
         
        thisform.referLabel.autoSize=.t.
        LOCAL tempFontSize
        FOR tempFontSize=8 TO 72
            thisform.referLabel.fontSize=tempFontSize
            IF (thisform.referLabel.height>nHeight) .or. (thisform.referLabel.width>nWidth)
                thisform.referLabel.fontSize=tempFontSize-1
            ENDIF
        ENDFOR
        MESSAGEBOX(thisform.referLabel.fontSize,64)
        IF thisform.referLabel.fontSize<=nBaseFontSize         
            RETURN nBaseFontSize
        ELSE
            RETURN thisform.referLabel.fontSize
        ENDIF
        ENDIF
    ENDPROC
      
    PROCEDURE Destroy
        CLEAR EVENTS
    ENDPROC
   
ENDDEFINE

报告老师,我低头不是因为我在装低调,是你问的问题,我真的不会答,,,
2015-12-23 15:30
不懂才问
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:大草原
等 级:贵宾
威 望:29
帖 子:1503
专家分:6593
注 册:2010-7-5
收藏
得分:0 
回复 5楼 liuxingang28
乱了   现在脑袋都要爆了   过两天再弄    清醒清醒     

报告老师,我低头不是因为我在装低调,是你问的问题,我真的不会答,,,
2015-12-24 14:55
不懂才问
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:大草原
等 级:贵宾
威 望:29
帖 子:1503
专家分:6593
注 册:2010-7-5
收藏
得分:0 
CLEAR ALL
CLOSE PROCEDURES
SET PROCEDURE TO "MyFormClass", "MyLoginForm"&&,"otherForm"
runShouliaoForm()

CLOSE PROCEDURES
&&CLOSE ALL
RETURN

PROCEDURE runShouliaoForm
    PUBLIC  shouliaoForm
    shouliaoForm=CREATEOBJECT("m1Form")   
    shouliaoForm.show
    READ EVENTS
    RETURN
ENDPROC

DEFINE CLASS m1Form as myForm
    showWindow=2
    caption="功能1——收料单"
    autoCenter=.t.
    windowType=1
    minWidth=this.Width
    minHeight=this.Height
    aspect=this.width/this.height        
    beforeWidth=this.width
    beforeHeight=this.Height
    formZoom=1
   
    ADD OBJECT referLabel as label&& WITH visible=.f.  &&参照控件,调试时可见
   
    ADD OBJECT titleLabel as label WITH caption="收 料 单",backColor=RGB(222,222,222)

    PROCEDURE Arrange
        IF this.width<>this.beforeWidth
            this.height=this.width/this.aspect
        ENDIF
        IF this.height<>this.beforeHeight
            this.width=this.height*this.aspect
        ENDIF
        this.formZoom=this.height/this.minHeight
        this.refresh
        this.beforeHeight=this.height
        this.beforeWidth=this.width
        
        WITH this.titleLabel
            .top=24*this.formZoom
            .left=(this.width-.width)/2
            .width=127*this.formZoom
            .height=29*this.formZoom
            &&.fontSize=thisform.fontReSize(.name,.height,.width,18,1)            
        ENDWITH
        
        IF this.height<>this.minHeight
            thisform.fontReSize(this.titleLabel.name,this.titleLabel.height,this.titleLabel.width,18,1)
        ELSE     
            this.titleLabel.fontSize=18
        ENDIF
        
    ENDPROC
   
    PROCEDURE fontReSize
        PARAMETERS nName,nHeight,nWidth,nFontSize,nClass
        IF nClass=1
            referControl="referLabel"
            this.&referControl..caption=this.&nName..caption
            this.&referControl..autoSize=.t.
        ENDIF
        LOCAL tempFontSize
        
        FOR tempFontSize=8 TO 72 STEP 1
            this.&referControl..fontSize=tempFontSize
            IF (this.&referControl..height>this.&nName..height).or.(this.&referControl..width>this.&nName..width)
                this.&nName..fontSize=tempFontSize-1
                RETURN
            ENDIF                        
        ENDFOR
*!*            IF tempFontSize>nFontSize
*!*                RETURN tempFontSize
*!*            ELSE
*!*                RETURN nFontSize
*!*            ENDIF         
    ENDPROC
   
    PROCEDURE Activate
        This.Arrange
    ENDPROC
   
    PROCEDURE Resize
        This.Arrange
    ENDPROC
   
    PROCEDURE Destroy
        CLEAR EVENTS
    ENDPROC
      
ENDDEFINE


大致是这样了    锁定窗口纵横比    计算出缩放比例    根据缩放比调整控件大小

再把控件的参数丢进方法   

方法中循环测试参照控件上最大能放多大字号  才能不超参数

最后得到比较合适的字号  

最后  还是不得不用参照控件   试了半天不参照    搞不出来   。。。

另一个新生产的问题  

我想用方法返回值   当作.fontSize的值    总说类型不对

messagebox(type(nFontSize))是U型,这是什么数据类型啊  。。。。。怎么转成数值

报告老师,我低头不是因为我在装低调,是你问的问题,我真的不会答,,,
2015-12-25 14:52
不懂才问
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:大草原
等 级:贵宾
威 望:29
帖 子:1503
专家分:6593
注 册:2010-7-5
收藏
得分:0 
程序代码:
    ADD OBJECT titleLabel as label WITH caption="收 料 单"
    ADD OBJECT howLineLabel as label WITH caption="本单有几项材料?"

            WITH this.titleLabel
            .fontBold=.t.
            .top=24*this.formZoom
            .left=209*this.formZoom
            .width=127*this.formZoom
            .height=29*this.formZoom
            .fontSize=thisform.fontReSize(.name,.height,.width,18,1)            
        ENDWITH
        WITH this.howLineLabel
            .top=this.titleLabel.top+this.titleLabel.height/2-.height/2
            .left=this.width-(this.width-(this.width/2+.width/2))/4*3
            .width=108*this.formZoom
            .height=12*this.formZoom
            .fontSize=thisform.fontReSize(.name,.height,.width,9,1)
        ENDWITH




程序代码:
    PROCEDURE fontReSize
        PARAMETERS nName,nHeight,nWidth,nFontSize,nClass
        IF nClass=1
            referControl="referLabel"
            this.&referControl..caption=this.&nName..caption
            this.&referControl..autoSize=.t.
            this.&nName..backColor=RGB(222,222,222)
        ENDIF 
        LOCAL tempFontSize
        FOR tempFontSize=nFontSize TO 72 STEP 1
            this.&referControl..fontSize=tempFontSize
            IF (this.&referControl..height>this.&nName..height).or.(this.&referControl..width>this.&nName..width)
                &&MESSAGEBOX(VARTYPE(tempFontSize),64)
                &&RETURN 
                EXIT  
            ENDIF                         
        ENDFOR
        MESSAGEBOX(VARTYPE(tempFontSize),64)
        IF this.height<>this.minHeight
            RETURN tempFontSize
        ELSE 
            RETURN nFontSize
        ENDIF         
    ENDPROC


解决了   用这个方法   传进去的字号   如果窗口没改变   字号就是默认的    如果窗口改了大小    字号就会变大

原来是RETURN和EXIT的区别没弄明白    真是   有些知识   光看书   永远记不住怎么用    还是要实践啊  

报告老师,我低头不是因为我在装低调,是你问的问题,我真的不会答,,,
2015-12-26 14:14
快速回复:这个方法错在呢?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024933 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved