CommandButton 控件(针对 Visual Basic 6.0 用户)
来源:百度文库 编辑:神马文学网 时间:2024/04/29 00:13:26
Visual Basic 6.0 中的 CommandButton 控件在 Visual Basic 2005 中被 Windows 窗体
概念差异
Default 和 Cancel 属性
在 Visual Basic 6.0 中,CommandButton 控件的布尔型 Default 和 Cancel 属性分别确定控件是否响应 Enter 或 Esc 键。
在 Visual Basic 2005 中,Button 控件不再具有 Default 和 Cancel 属性。
Value 属性
在 Visual Basic 6.0 中,CommandButton 控件的布尔型的 Value 属性指示是否已选择该控件;将该属性设置为 True 将调用按钮的 Click 事件。
在 Visual Basic 2005 中,Button 控件不再具有 Value 属性。可以使用
Style、Picture、DownPicture 和 DisabledPicture 属性
在 Visual Basic 6.0 中,将 CommandButton 控件的“Style”属性设置为“1 – Graphical”可更改控件的外观以显示图像。Picture、DownPicture 和 DisabledPicture 属性用于分配为响应状态更改所显示的图像。例如,单击 CommandButton 控件时,显示 DownPicture 图像;如果禁用该控件,则显示 DisabledPicture 图像。
Visual Basic 2005 不再支持 Style、Picture、DownPicture 和 DisabledPicture 属性。Style 属性不再是必需的;将图片指定给
MaskColor 属性
在 Visual Basic 6.0 中,CommandButton 控件的 MaskColor 属性用于定义透明的颜色,以便能够显示背景图像。若要使用此属性,“Style”属性必须设置为“Graphical”,UseMaskColor 属性必须设置为 True,并且必须将一幅位图赋给 Picture 属性。
在 Visual Basic 2005 中,没有 MaskColor 属性的直接等效项。但是可以使用
其他差异
此外,还有许多适用于所有控件的概念性差异,例如数据绑定、字体处理、拖放、帮助支持等方面的差异。有关更多信息,请参见适用于 Visual Basic 6.0 用户的 Windows 窗体控件。
CommandButton 控件的代码更改
下面的代码示例演示 Visual Basic 6.0 和 Visual Basic 2005 在编码方法上的不同之处。
设置 Default 和 Cancel 按钮代码更改
下面的示例演示将窗体的两个按钮设置为 default 和 cancel 按钮。
' Visual Basic 6.0 ' Set the first button to respond to the Enter key. Command1.Default = True ' Set the second button to respond to the Esc key. Command2.Cancel = True
' Visual Basic 2005 ' Set the first button to respond to the Enter key. Me.AcceptButton = Button1 ' Set the second button to respond to the Esc key. Me.CancelButton = Button2
为按钮添加透明度的代码更改
下面的示例演示定义包含图像的按钮上的透明区域的方法;图像上的所有白色部分将变为透明。
' Visual Basic 6.0 ' Assumes a picture has been assigned to the Picture property ' and that the Style property has been set to Graphical. Command1.UseMaskColor = True Command1.MaskColor = vbWhite
' Visual Basic 2005 ' Assumes a picture has been assigned to the BackgroundImage property. Dim ButtonBitmap As New System.Drawing.Bitmap(Button1.BackgroundImage) ButtonBitmap.MakeTransparent(System.Drawing.Color.White) Button1.BackgroundImage = ButtonBitmap
CommandButton 控件的属性、方法和事件的等效项
下面几个表列出了 Visual Basic 6.0 中的属性、方法和事件及它们的 Visual Basic 2005 等效项。具有相同的名称和行为的属性、方法和事件未予列出。如果适用,常数在属性或方法的下面缩进。除非另外说明,否则所有 Visual Basic 2005 枚举都映射到
下面的表列出指向解释行为差异的主题的链接。如果 Visual Basic 2005 中没有直接等效项,则提供指向介绍替换项的链接。
属性
Appearance
新的实现。有关更多信息,请参见 Appearance 和 BorderStyle 属性(针对 Visual Basic 6.0 用户)。
BackColor
颜色在 Visual Basic 2005 中以不同方式处理。有关更多信息,请参见颜色处理(针对 Visual Basic 6.0 用户)。
Cancel
CancelButton(Form 对象)
Caption
Container
Default
AcceptButton(Form 对象)
DisabledPicture
DownPicture
新的实现。有关更多信息,请参见 Style 属性(针对 Visual Basic 6.0 用户)。
DragIcon
DragMode
新的实现。有关更多信息,请参见拖放(针对 Visual Basic 6.0 用户)。
Font
FontBold
FontItalic
FontName
FontSize
FontStrikethrough
FontUnderline
字体在 Visual Basic 2005 中以不同方式处理。有关更多信息,请参见 Font 对象(针对 Visual Basic 6.0 用户)。
Height
坐标在 Visual Basic 2005 中以不同方式处理。有关更多信息,请参见坐标系统(针对 Visual Basic 6.0 用户)。
HelpContextID
新的实现。有关更多信息,请参见帮助支持(针对 Visual Basic 6.0 用户)。
HWnd
Index
新的实现。有关更多信息,请参见控件数组(针对 Visual Basic 6.0 用户)。
Left
坐标在 Visual Basic 2005 中以不同方式处理。有关更多信息,请参见坐标系统(针对 Visual Basic 6.0 用户)。
MaskColor
新的实现。有关更多信息,请参见 MaskColor(针对 Visual Basic 6.0 用户)。
MouseIcon
新的实现。有关更多信息,请参见无法设置自定义 MousePointer。
MousePointer
有关常数的列表,请参见 MousePointer(针对 Visual Basic 6.0 用户)。
OLEDropMode
新的实现。有关更多信息,请参见拖放(针对 Visual Basic 6.0 用户)。
Parent
Picture
Image
RightToLeft
Style
新的实现。有关更多信息,请参见 Style 属性(针对 Visual Basic 6.0 用户)。
ToolTipText
有关更多信息,请参见工具提示支持(针对 Visual Basic 6.0 用户)。
Top
坐标在 Visual Basic 2005 中以不同方式处理。有关更多信息,请参见坐标系统(针对 Visual Basic 6.0 用户)。
UseMaskColor
新的实现。有关更多信息,请参见 MaskColor(针对 Visual Basic 6.0 用户)。
Value
新的实现。PerformClick 方法和将 Value 设置为 True 的效果相同;对于 Value 属性的任何其他用途,没有等效项。
WhatsThisHelpID
新的实现。有关更多信息,请参见帮助支持(针对 Visual Basic 6.0 用户)。
Width
坐标在 Visual Basic 2005 中以不同方式处理。有关更多信息,请参见坐标系统(针对 Visual Basic 6.0 用户)。
方法
Drag
新的实现。有关更多信息,请参见拖放(针对 Visual Basic 6.0 用户)。
Move
坐标在 Visual Basic 2005 中以不同方式处理。有关更多信息,请参见坐标系统(针对 Visual Basic 6.0 用户)。
OLEDrag
新的实现。有关更多信息,请参见拖放(针对 Visual Basic 6.0 用户)。
SetFocus
ShowWhatsThis
新的实现。有关更多信息,请参见帮助支持(针对 Visual Basic 6.0 用户)。
ZOrder
事件
DragDrop
DragOver
新的实现。有关更多信息,请参见拖放(针对 Visual Basic 6.0 用户)。
GotFocus
LostFocus
OLECompleteDrag
OLEDragDrop
OLEDragOver
OLEGiveFeedback
OLESetData
OLEStartDrag
新的实现。有关更多信息,请参见拖放(针对 Visual Basic 6.0 用户)。
升级说明
使用升级向导升级 Visual Basic 6.0 应用程序时,任何 CommandButton 控件将升级到 Windows 窗体 Button 控件,并且更新代码以使用等效的属性、方法和事件。没有等效项或可能存在行为差异的地方,将在代码中插入注释和指向帮助主题的链接。
应用程序升级到 Visual Basic 2005 后,如果 Style 属性设置为 1 – Graphical,则升级后控件的 FlatStyle 属性设置为 Standard,任何设计时分配给 Picture 属性的图像都将分配给升级后控件的 Image
属性。
如果设计时或运行时设置了 DownPicture 或 DisabledPicture 属性,则需要修改升级后的应用程序,使之使用 ImageList 控件。有关更多信息,请参见如何:在升级应用程序中模拟 Visual Basic 6.0 三态控件。
升级向导不升级使用 MaskColor 属性的代码。代码中将插入升级警告。运行应用程序前需要修改代码。