我正在尝试使用特定字体创建文本字段派生类。该字段可以正确创建,但字体不起作用:
#lang racket/gui
; my particular font:
(define (myfont size) (make-object font% size 'modern 'normal 'bold))
(define myframe (new frame% [width 600] [label "MyFrame"]))
(new text-field% [parent myframe] [label "Usual text-field; font works here:"] [font (myfont 14)])
; Following is my text-field derived class with a particular font:
(define mytf% (class text-field% (field (font (myfont 14))) (super-new)))
(new mytf% [parent myframe] [label "My text-field derived class; font does not work here:"])
(send myframe show #t)
问题出在哪里?如何解决?感谢您的意见/解答。
答案 0 :(得分:1)
问题是font
不是text-field%
中的公共字段。
因此,(field (font (myfont 14)))
会在mytf%
中显示一个新字段,但text-field%
不会使用该字段。
解决方案是在实例化文本字段时传递字体信息:
(define mytf%
(class text-field%
(super-new [font (myfont 14)])))