VB ActiveX UserControls

ASP.NET Web Forms深度解析:从Page生命周期到生产部署 ASP.NET Web Forms是微软早期面向Windows平台的Web开发模型,其核心在于事件驱动、服务端控件与ViewState状态维持机制。理解其Page生命周期、Postback协议映射、HttpModule管道介入等底层原理,不仅有助于维护大量现存的.NET Framework遗留系统,更能反向深化对现代框架(如ASP.NET Core中间件、React状态管理)设计哲学的认知。在政务、金融、央企等强合规场景中,Web Forms仍承担着关键业务系统支撑任务,尤其在需零操作习惯变更、快速改造VB 阅读详情

VB ActiveX UserControls

VB自定义控件默认是Implements了UserControl类,自定义控件的事件都可以通过实现UserControl的事件来实现

UserControl类常用事件包括:

Event AccessKeyPress(KeyAscii As Integer)

    Occurs when the user of the control presses one of the control's access keys, or when the Enter key is pressed when the developer has set the Default property to True, or when the Escape key is pressed when the developer has set the Cancel property to True.  The Default property and the Cancel property are enabled by the author of the control setting the DefaultCancel property to True.

 

Event  Click()                    Occurs when the user presses and then releases a mouse button over an object.

Event DblClick()     Occurs when the user presses and releases a mouse button

and then presses and releases it again over an object.

 

Event DragDrop(Source As Control, X As Single, Y As Single)

                     Occurs when a drag-and-drop operation is completed.

Event DragOver(Source As Control, X As Single, Y As Single, State As Integer)

                     Occurs when a drag-and-drop operation is in progress.

 

Event EnterFocus()    Occurs when focus enters the control. The control itself could be receiving focus,

or a constituent control could be receiving focus.

Event ExitFocus()    Occurs when focus leaves the control. The control itself could be losing focus,

or a constituent control could be losing focus.

Event GotFocus()     Occurs when an object receives the focus.

Event LostFocus()    Occurs when an object loses the focus.

 

Event GetDataMember(DataMember As String, Data As object)

                     Occurs when a data consumer is asking this data source for one of it's data members.

 

Event Show()            Occurs when the control's Visible property changes to True.

Event Hide()            Occurs when the control's Visible property changes to False.

Event HitTest(X As Single, Y As Single, HitResult As Integer)

                     Occurs in a windowless user control in response to mouse activity.

 

Event Initialize()    Occurs when an application creates an instance of a Form, MDIForm, or class.

Event Terminate()    Occurs when all references to an instance of a Form, MDIForm, or class

are removed from memory.

 

Event InitProperties()    Occurs the first time a user control or user document is created.

Sub PropertyChanged([PropertyName])  

                     Notifies the container that a property on a User Control has been changed.

Event ReadProperties(PropBag As PropertyBag)

Occurs when a user control or user document is asked to read its data from a file.

Event WriteProperties(PropBag As PropertyBag)

Occurs when a user control or user document is asked to write its data to a file.

 

Event KeyDown(KeyCode As Integer, Shift As Integer)

                     Occurs when the user presses a key while an object has the focus.

Event KeyPress(KeyAscii As Integer)

                     Occurs when the user presses and releases an ANSI key.

Event KeyUp(KeyCode As Integer, Shift As Integer)

                     Occurs when the user releases a key while an object has the focus.

Event MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

    Occurs when the user presses the mouse button while an object has the focus.

Event Paint()        Occurs when any part of a form or PictureBox control is moved, enlarged, or exposed.

Event Resize()        Occurs when a form is first displayed or the size of an object changes


本例通过实现一个只限输入数字的文本框的自定义控件为例,来了解VB自定义控件的实现

1. 创建一自定义NumericInput,在自定义控件中加入一文本框txtInput

2. 实现当改变自定义控件大小时,txtInput文本框能自动填充满整个自定义控件区域。可通过Implements UserControl的Resize事件

Public Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long, ByVal x As Long, ByVal Y As Long, _

             ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long

   

    Public Function Twip2Pixel(x) As Integer

        Dim cx      As Long

        Dim cy      As Long

        cx = Screen.TwipsPerPixelX

        cy = Screen.TwipsPerPixelY

        Twip2Pixel = x / cx

    End Function

   

    Private Sub MoveControl(ctrl as Control, ByVal left As Integer, ByVal top As Integer, _

        ByVal width As Integer, ByVal Height As Integer)

        Dim lResult As Long

        On Error Resume Next

       

If width < 0 Then width = 0

        If height < 0 Then height = 0

        lResult = MoveWindow(ctrl.hwnd, _

Twip2Pixel(left),Twip2Pixel(top), Twip2Pixel(width),Twip2Pixel(height),1)

        '* 如果改变大小失败,则直接改变

        If lResult = 0 Then  ctrl.Move left, top, width, height

    End Sub

 

    Private Sub UserControl_Resize()

        MoveControl txtInput, 0, 0, UserControl.ScaleWidth, UserControl.ScaleHeight

    End Sub

 

3.  为自定义控件添加属性

    为控件添加Alignment属性,属性有四个选项 Left Justify/ Right Justify/ Center/ General来控制文本框的对齐

    Public Enum AlignmentConstants

        [Left Justify] = 0

        [Right Justify] = 1

        [Center] = 2

        [General] = 3

        [User Defined] = 4

End Enum

 

    private m_Alignment As AlignmentConstants

      '属性必须是公共的,选项是枚举/布尔类型

    Public Property Get Alignment() As AlignmentConstants

        Alignment = m_Alignment

    End Property

    Public Property Let Alignment(value As AlignmentConstants)

        m_Alignment = value

        PropertyChanged "Alignment"

    End Property

    ReadProperties 和 WriteProperties 事件用来保存和读取属性改变后的值, 否则每次更新控件都是使用默认属性值

    Private Sub UserControl_ReadProperties(PropBag As PropertyBag)

        Alignment = PropBag.ReadProperty("Alignment", 0)

    End Sub

   

    Private Sub UserControl_WriteProperties(PropBag As PropertyBag)

        Call PropBag.WriteProperty("Alignment", Alignment, 0)

End Sub

4.  为自定义控件添加事件

    为自定义控件添加Click事件,当单击txtInput时发生

    Event Click()

    Private Sub txtInput_Click()

        RaiseEvent Click

    End Sub

 

5.  扩充,将自定义控件扩充为组合的控件

    Win32 API提供的 DrawFrameControl函数用于描绘一个标准控件。可描绘一个按钮或滚动条的帧,在本例中,将txtInput扩充,在txtInput右侧增加一按钮,使txtInput成为一个选择框

    DrawFrameControl API函数定义如下

    Declare Function DrawFrameControl Lib "user32" (

        ByVal hDC As Long, _                    '要在其中作画的设备场景

        lpRect As RECT, _                       '指定帧的位置及大小的一个矩形

        ByVal un1 As Long, _                    '指定帧类型的一个常数

        ByVal un2 As Long _                     '一个常数,指定欲描绘的帧的状态。

        ) As Long                               '非零表示成功,零表示失败

    '帧类型常数包括

    Private Const DFC_CAPTION = 1            'Title bar

    Private Const DFC_MENU = 2               'Menu

    Private Const DFC_SCROLL = 3             'Scroll bar

    Private Const DFC_BUTTON = 4             'Standard button

   

    '帧状态常数包括

    Private Const DFCS_CAPTIONCLOSE = &H0    'Close button

    Private Const DFCS_CAPTIONMIN = &H1      'Minimize button

    Private Const DFCS_CAPTIONMAX = &H2      'Maximize button

    Private Const DFCS_CAPTIONRESTORE = &H3  'Restore button

    Private Const DFCS_CAPTIONHELP = &H4     'Windows 95 only:Help button

 

    Private Const DFCS_MENUARROW = &H0       'Submenu arrow

    Private Const DFCS_MENUCHECK = &H1       'Check mark

    Private Const DFCS_MENUBULLET = &H2      'Bullet

    Private Const DFCS_MENUARROWRIGHT = &H4

 

    Private Const DFCS_SCROLLUP = &H0        'Up arrow of scroll bar

    Private Const DFCS_SCROLLDOWN = &H1      'Down arrow of scroll bar

    Private Const DFCS_SCROLLLEFT = &H2      'Left arrow of scroll bar

    Private Const DFCS_SCROLLRIGHT = &H3     'Right arrow of scroll bar

    Private Const DFCS_SCROLLCOMBOBOX = &H5  'Combo box scroll 'bar

    Private Const DFCS_SCROLLSIZEGRIP = &H8         'Size grip

    Private Const DFCS_SCROLLSIZEGRIPRIGHT = &H10   'Size grip in bottom-right corner of window

 

    Private Const DFCS_BUTTONCHECK = &H0     'Check box

    Private Const DFCS_BUTTONRADIO = &H4     'Radio button

    Private Const DFCS_BUTTON3STATE = &H8    'Three-state button

    Private Const DFCS_BUTTONPUSH = &H10     'Push button

 

    Private Const DFCS_INACTIVE = &H100      'Button is inactive (grayed)

    Private Const DFCS_PUSHED = &H200        'Button is pushed

    Private Const DFCS_CHECKED = &H400       'Button is checked

 

    Private Const DFCS_ADJUSTRECT = &H2000   'Bounding rectangle is adjusted to exclude the surrounding

                                            'edge of the push button

    Private Const DFCS_FLAT = &H4000         'Button has a flat border

    Private Const DFCS_MONO = &H8000         'Button has a monochrome border

   

    '绘制文本常量

    Private Const DT_CENTER = &H1

    Private Const DT_LEFT = &H0

    Private Const DT_RIGHT = &H2

    Private Const DT_VCENTER = &H4

    Private Const DT_SINGLELINE = &H20

   

    Private Sub draw()

        If txtInput.Locked Or Not txtInput.Enabled Then

            MoveControl txtInput, 0, 0, UserControl.ScaleWidth, UserControl.ScaleHeight

        Else

            If UserControl.BorderStyle = 1 Then

                MoveControl txtInput, 0, 0, UserControl.width - 300, UserControl.Height

            Else

                MoveControl txtInput, 0, 0, UserControl.width - 250, UserControl.Height

            End If

            Call drawPushButton(False)

        End If

    End Sub

 

    Private Sub drawPushButton(pushed As Boolean)           '* 绘制按钮

        Dim rc      As RECT

        GetWindowRect UserControl.hwnd, rc

        rc.Right = rc.Right - rc.Left

        If UserControl.BorderStyle = 1 Then

            If UserControl.Appearance = 1 Then

                rc.Bottom = rc.Bottom - rc.Top - 3

                rc.Right = rc.Right - 3

            Else

                rc.Bottom = rc.Bottom - rc.Top - 2

                rc.Right = rc.Right - 2

            End If

        Else

            rc.Bottom = rc.Bottom - rc.Top

        End If

 

        rc.Left = Twip2Pixel(txtInput.width)

        rc.Top = 0

        UserControl.Cls

        DrawFrameControl UserControl.hdc, rc, DFC_BUTTON + DFCS_BUTTONPUSH, _

            DFCS_ADJUSTRECT + DFCS_BUTTON3STATE

       

        '* 绘制文本

        If pushed Then

            rc.Right = rc.Right + 1

            rc.Bottom = rc.Bottom + 1

        End If

        DrawText UserControl.hdc, "...", -1, rc, DT_CENTER + DT_VCENTER + DT_SINGLELINE

    End Sub

   

    '在UserControl Show事件中绘制按钮

    Private Sub UserControl_Show()

        Call draw

    End Sub

 

    '响应按钮点击事件

    '实现UserControl_MouseDown事件

    Event ButtonClick()

    Private Sub UserControl_MouseDown(Button As Integer, Shift As Integer, x As Single, Y As Single)

        If Button = 0 Then

            RaiseEvent ButtonClick

        End If

    End Sub

vb6.0用户自定义控件 最近发现的,挺好用的,想做成类似qq菜单的那种效果 思路 在我的上传上找 立即下载

相关推荐

UserControl的应用实例,UserControl1.htmlVB源代码

UserControl的应用实例,UserControl1.htmlVB源代码

VB6 运行时错误‘374’ 激活控件‘VB.UserControl’失败

VB6项目,更新了一些内容,生成了新版的exe文件,放到设备上运行,提示 “运行时错误 374:激活控件‘VB.UserControl’失败。这个控件可能与您的应用程序不兼容。确定您使用的这个版本的控件是由您的应用程序所提供的。” 进行了多种尝试,仍未解决问题,不过发现了规律: 设备上的控制电脑装的是系统是XP,较早版本的exe可以在设备上运行,而我接手之后重新生成的exe无法运行。 ...

小鹰信息技术服务部 6445

VB.NET制作自己控件(Usercontroll)

VB.NET制作自己控件(Usercontroll) 最基础vb.net 控件教程 把功能封装在控件里面

如何给vb的UserControl添加属性、方法和事件?

一、属性的派生 Public Property Let 属性名(ByVal NewValue As 类型名) PropertyChanged "属性名" End Property Public Property Get 属性名() As 类型名 End Property 如果是只读的属性,缺省Let过程即可。 二、方法的派生 Public Sub 方法名(参数表) End Sub Publ

autumn20080101的专栏 3656

关于并网继电器的继电器自检逻辑及实现方式

对于常规的光伏并网逆变器来说,继电器控制至关重要。继电器一般位于逆变电感后,共模电感前,用于将逆变电压与电网电压脱开,一般国外有双继电器的安规强制认证要求,国内目前只需要单继电器要求(后续应该会有双继电器要求,个人感觉)

weixin_29982209的博客 2630

433M无线遥控器EV1527协议解码实战:从逻辑分析到代码优化

本文详细解析了433M无线遥控器EV1527协议的实战解码过程。从使用逻辑分析仪抓取波形、理解同步头与数据位编码原理开始,逐步深入代码实现。文章重点对比了原始定时器轮询法的痛点,并提出了基于“边沿捕获+时间戳”的优化方案,构建了高效、可移植且具备抗干扰能力的解码引擎,最后分享了跨平台移植的核心技巧。

weixin_29168813的博客 941

[VB]UserControl中的主要事件

[VB]UserControl中的主要事件 用VB创建ActiveX控件避不可免地与UserContro1打交道,准确理解其含义是保证程  序正确运行的关键。以下结合本人的经验,简要地解释VB5中UserControl的主要事件,  借此与大家交流:  ◆ Initia1ize Event       在控件的实例被创建或重新创建时发生,它总是控件实例生命周期内的第一个事件

autumn20080101的专栏 2905

IAR编译相同工程生产hex文件checksum不一致问题

IAR Checksum

xqw19891201的博客 1389

VB 自定义控件-UserControl

1--默认属性-- (1)属性 GET中 加上AttributeValue.VB_UserMemId = 0 '--不过貌似有问题 (2) Private Sub UserControl_InitProperties()   Text1.Text = Ambient.DisplayName  End Sub (3) “Tools”-“Procedure Attributes”-选择目标...

weixin_30279751的博客 1006

LabVIEW状态机实战:用STM32+DHT11搭建温湿度监测系统(附完整VI源码)

本文详细介绍了如何利用LabVIEW状态机模式与STM32微控制器、DHT11温湿度传感器构建温湿度监测系统。通过硬件选型、状态机设计、LabVIEW程序实现及系统优化等环节,提供了一套完整的解决方案,并附有VI源码,助力开发者快速实现嵌入式温湿度监测应用。

weixin_42549723的博客 524

手把手教你学GPU的KMD专栏--3.1 设备初始化流程深度解析

本文深入解析了KMD(内核模式驱动)设备初始化流程,这是GPU驱动开发最基础且关键的环节。初始化流程包括6个核心阶段:KMD模块加载、PCIe设备探测匹配、GPU硬件初始化、显存分配映射、中断系统配置和设备注册。每个阶段都有详细步骤解析,涉及关键数据结构和错误处理机制。文章还分析了常见问题(驱动加载失败、显存分配失败、中断配置失败)的解决方案,并指出未来趋势将向动态初始化、安全增强和AI优化方向发展。正确高效的初始化流程是确保GPU被操作系统安全使用的前提,也是后续内存管理、任务调度等功能的基础。

MHD0815的博客 269

VB Decompiler v3.9 has been released (02.03.08)

 Whats new in this version:- Parsing LateIdLdVar opcode- Parsing LateIdSt opcode- Parsing CastAdVar opcode- Detecting type of property (Let, Set, Get)- New powerful database for external Ac

Linhanshi Blog 765

【AI for Medecine】吴恩达医学图像AI专项课程(诊断、预测、治疗)

近期需要简单了解AI4Science上的一些应用,看到吴恩达大佬的专项课程,于是开始来个“全面”的了解--医学人工智能(诊断、预测、治疗)。

图挖掘领域,新晋砖家 ☞ 未来可期,欢迎和静静一起学习交流吖 791

vb.net 如何在同一页面,添加相同的usercontrol

核心思想:对操作的控件ID唯一。 核心代码: 解题思想:服务器控件会自动生成一个唯一的ID,但非服务器控件和对应的js事件不会。 代码: 后台: 在页面load方法中: Me.txt_Client.Attributes.Add("onKeydown", "return " + Me.ClientID + "_ClientTextChanged(this)")       JS:

u011187194的专栏 879

YOLOv8进阶:SEAM注意力与Repulsion Loss双剑合璧,突破遮挡检测瓶颈

做目标检测时,最头疼的莫过于目标被遮挡的场景——行人被树木挡住一半、车辆被广告牌遮挡部分轮廓……这些情况往往让模型“犯迷糊”。但现在,有了SEAM注意力模块和Repulsion Loss排斥损失,我们就能让YOLOv8在遮挡场景下也能“拨开迷雾见真章”。这篇教程会带你一步步理解这两个技术,并亲手把它们融入YOLOv8,让你的检测模型在复杂场景下也能稳如泰山。

FJN110的博客 238

UFAST车道线检测 Ultra-Fast-Lane-Detection 从环境搭建到复现完成(一)

UFAST车道线检测 Ultra-Fast-Lane-Detection 从环境搭建到复现完成(一)

m0_46364958的博客 4347

VB6.0中用户类和数据源类的设计和使用技术

<br />---- Visual Basic 6.0是面向对象的编程语言,允许开发人员设计自定义类。用户自定义类(Class)是VB 6.0中实现软件重用的最基本方法,也是设计和使用Active X EXE/DLL部件的技术基础。在VB 6.0中可以用手工的方式直接设计类,也可用类设计器设计类,而且,VB 6.0提供了类向导(如数据源类向导,复杂数据源类向导)供快速设计复杂类。本文基本上以笔者设计的通讯电源电压监控为例介绍定义和使用类(特别是类的自定义事件)的方法(包括属性、方法、自定义事件),并将讨论包

netcellsoft的专栏 1441

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

DrawFrameControl绘制按钮

CDC类中的DrawFrameControl函数,提供了在DC中绘制按钮的方法,而不必采用动态创建按钮的形式。函数原型如下: BOOL DrawFrameControl( LPRECT lpRect, UINT nType, UINT nState ); 参数说

极简Qt 1万+

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

用VB无窗口透明Usercontrol编写透明浮动按钮

使用无窗口透明控件,好处是控件不是从窗口类继承而来的,可以节省一些内存资源,难点是鼠标控制和坐标计算,缺点是无法直接响应键盘事件。而且,需要注意的是,在Paint事件里,坐标是从(0,0)开始的,而在其它地方,坐标是相对于容器的。缺点是设计时,无法用鼠标点选控件(只能用键盘移动),微软公司也在MSDN里说了这是一个BUG,但至今未解决。    好了,废话俺不说了,打开VB6,新建

lyserver的专栏 3517

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

WinAPI: DrawFrameControl - 绘制控件

为什么80%的码农都做不了架构师?>>> ...

weixin_33979363的博客 329

vim删除重复行的函数

最近在vim使用中需要用到删除重复行,载网上找了一下发现以下函数可以用来删除一个重复行function! Del()    if getline(".") == getline(line(".") - 1)        norm dd    endifendfunction于是,将上面的函数和以前的在文件每一行插入行号的函数结合,修改为以下函数,用于删除整个文档的行function DelDup

Twent的专栏 4975
上一篇: CallBack and Hooks
下一篇: 抉择
Twent
博客等级 码龄23年 7粉丝 29原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值