Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Winapi 我可以进入VB6文本框控件';使用的字体强制的最小高度是多少?_Winapi_Vb6 - Fatal编程技术网

Winapi 我可以进入VB6文本框控件';使用的字体强制的最小高度是多少?

Winapi 我可以进入VB6文本框控件';使用的字体强制的最小高度是多少?,winapi,vb6,Winapi,Vb6,我有一个文本框控件,仅限于数字输入。它的字体是Arial,标准,10磅。容器的ScaleMode设置为像素 由于文本框将只接受和显示数字,我不需要所有的空格,尤其是在垂直维度中,所以我在设计器中调整文本框的高度。我的目标是一个20像素高的文本框控件 尝试在属性窗口中设置“高度”属性会将高度捕捉为24像素 很明显,控件的高度是由使用的字体强制的。使用Arial,Standard,7 pt.,我可以得到我想要的20 px的高度。只是我需要一个10磅的字体大小 使用鼠标时,调整大小在设计器中起作用(例

我有一个文本框控件,仅限于数字输入。它的字体是Arial,标准,10磅。容器的ScaleMode设置为像素

由于文本框将只接受和显示数字,我不需要所有的空格,尤其是在垂直维度中,所以我在设计器中调整文本框的高度。我的目标是一个20像素高的文本框控件

尝试在属性窗口中设置“高度”属性会将高度捕捉为24像素

很明显,控件的高度是由使用的字体强制的。使用Arial,Standard,7 pt.,我可以得到我想要的20 px的高度。只是我需要一个10磅的字体大小

使用鼠标时,调整大小在设计器中起作用(例如,我可以达到19像素)。但在运行时,高度会回到24像素

我试图在初始化事件中欺骗VB,首先给它一个小字体,调整高度,然后将字体大小重置为原始大小。不,24像素

我还尝试使用Window的API函数MoveWindow。该框显示为24像素


是否有其他可能有用的API函数,或者是我唯一可能编写自己的VB用户控件的函数?(我可以制作一个由TextBox控件组成的用户控件作为其唯一的组成控件,然后将其顶部放入负片,用户控件的高度达到所需的高度。)

好的,所以我选择了stony road,创建了一个适合我的用户控件。如果你有同样的问题,那么这个问题就解决了

添加ActiveX用户控件类型的新项目。将用户控件命名为UTextBox。将用户控件的字体修改为所需的字体(Arial、Standard、10 pt.),并将其ScaleMode属性设置为像素。将这两个文件保存到新的项目文件夹中

将TextBox控件放置在用户控件的位置0,0处,并将其命名为cTextBox。然后,整个核心功能都包含在Resize事件中

Option Explicit

'==============================================================================
'On resizing the control.
'------------------------------------------------------------------------------
Private Sub UserControl_Resize()
    Dim lHeightDiff As Long

    With cTextBox
        'Let the TextBox control inherit the user control's new dimensions.
        .Height = UserControl.ScaleHeight
        .Width = UserControl.ScaleWidth

        'The text box is always centered vertically on the same-sized or smaller
        'user control, so that the text still is displayed also when the
        'TextBox is larger than the user control's height.
        .Top = (UserControl.ScaleHeight - .Height) / 2
    End With
End Sub
'==============================================================================
接下来是一项繁琐的任务,要传递给文本框控制所有属性、方法和事件,或者至少要传递给您感兴趣的所有属性、方法和事件

'==============================================================================
'Pass-through properties. Keep it alphabetical.
'------------------------------------------------------------------------------
Public Property Let Alignment(NewAlignment As AlignmentConstants)
    cTextBox.Alignment = NewAlignment
    PropertyChanged "Alignment"
End Property
'------------------------------------------------------------------------------
Public Property Get Alignment() As AlignmentConstants
    Alignment = cTextBox.Alignment
End Property
'------------------------------------------------------------------------------
Public Property Let Enabled(NewState As Boolean)
    cTextBox.Enabled = NewState
    PropertyChanged "Enabled"
End Property
'------------------------------------------------------------------------------
Public Property Get Enabled() As Boolean
    Enabled = cTextBox.Enabled
End Property
'------------------------------------------------------------------------------
Public Property Get hWnd() As Long      'Read-only.
    hWnd = cTextBox.hWnd
End Property
'------------------------------------------------------------------------------
Public Property Let Text(NewText As String)
    cTextBox.Text = NewText
    PropertyChanged "Text"
End Property

...     
'==============================================================================
有(至少)两个特殊属性应该被截取并应用于用户控件本身:外观和边框样式,因为文本框可以放置在用户控件之外,并且会使这些属性部分不可见。对于这两个属性,我无法找到它们的枚举(如属性窗口中所示),因此滚动了自己的枚举(存在命名约定,如果愿意,请使用自己的名称):

以下是两个特殊属性:

'==============================================================================
'All properties, methods and events which are currently needed are mediated
'to and from the outside world and the TextBox control, with the exception of
'BorderStyle and Appearance, which are properties of the user control, so that
'a frame can be displayed even when it would not fit into the TextBox control.
'------------------------------------------------------------------------------
Public Property Let Appearance(NewAppearance As ETxB_Appearance)
    UserControl.Appearance = NewAppearance
    PropertyChanged "Appearance"
End Property
'------------------------------------------------------------------------------
Public Property Get Appearance() As ETxB_Appearance
    Appearance = UserControl.Appearance
End Property
'------------------------------------------------------------------------------
Public Property Let BorderStyle(NewStyle As ETxB_BorderStyle)
    UserControl.BorderStyle = NewStyle
    PropertyChanged "BorderStyle"
End Property
'------------------------------------------------------------------------------
Public Property Get BorderStyle() As ETxB_BorderStyle
    BorderStyle = UserControl.BorderStyle
End Property
'==============================================================================
现在对所有方法执行相同的操作

现在,对于所有事件(当然,您还需要添加事件声明)

最后,别忘了编写属性包例程,使您的用户控件具有持久属性

'==============================================================================
'Initializing properties.
'------------------------------------------------------------------------------
Private Sub UserControl_InitProperties()
    UserControl.Appearance = TxBApp_2D
    ...
    cTextBox.Alignment = vbLeftJustify
    ...
End Sub
'==============================================================================

'==============================================================================
'Reading properties.
'------------------------------------------------------------------------------
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
    With PropBag
        UserControl.Appearance = .ReadProperty("Appearance", TxBApp_2D)
        ...
        cTextBox.Alignment = .ReadProperty("Alignment", vbLeftJustify)
        ...
    End With
End Sub
'==============================================================================

'==============================================================================
'Write properties.
'------------------------------------------------------------------------------
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
    With PropBag
        .WriteProperty "Appearance", UserControl.Appearance, TxBApp_2D
        ...
        .WriteProperty "Alignment", cTextBox.Alignment, vbLeftJustify
        ...
    End With
End Sub
'==============================================================================
现在,自动最低高度强制执行已不复存在。例如,我们可以将标准的10磅字体放入14像素高的控件中


我不知道为什么,但如果删除现有的文本框,添加一个新的文本框,使用鼠标(而不是属性网格)指定高度,然后才将字体设置为Arial 10pt,它在运行时将保持低高度。以不同的顺序执行此操作将重置高度。“尝试在属性窗口中设置height属性会将高度捕捉到24像素。”-这是因为高度是在DLU中设置的(请参阅)。@GSerg,你是对的,+1用于查找此值-只是我不会使用它:它似乎比黑客攻击更糟糕,因为“我们不知道它为什么起作用。”(可能是一个19年前的bug,将在下次更新时修复…)@IInspectable,我不使用对话框。@赫伯:如果您使用的是资源编辑器,那么您就是在创建一个对话框。它可以在VB6中被称为Form,但它使用相同的API调用从资源脚本创建它,就像其他任何对话框一样。同样的规则适用于DLU中的测量元素(不是像素)。哇,您真的想要回这4个像素!
'==============================================================================
'Initializing properties.
'------------------------------------------------------------------------------
Private Sub UserControl_InitProperties()
    UserControl.Appearance = TxBApp_2D
    ...
    cTextBox.Alignment = vbLeftJustify
    ...
End Sub
'==============================================================================

'==============================================================================
'Reading properties.
'------------------------------------------------------------------------------
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
    With PropBag
        UserControl.Appearance = .ReadProperty("Appearance", TxBApp_2D)
        ...
        cTextBox.Alignment = .ReadProperty("Alignment", vbLeftJustify)
        ...
    End With
End Sub
'==============================================================================

'==============================================================================
'Write properties.
'------------------------------------------------------------------------------
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
    With PropBag
        .WriteProperty "Appearance", UserControl.Appearance, TxBApp_2D
        ...
        .WriteProperty "Alignment", cTextBox.Alignment, vbLeftJustify
        ...
    End With
End Sub
'==============================================================================