关于自制控件中的click事件

mendel 2003-08-24 06:00:06
控件中有一个LABEL,一个PICTURE,(LABEL在PICTURE中)
我现在设置了PICTURE的CLICK事件,有效,可是为什么设置LABEL的CLICK就无效呢?
这是PICTURE的CLICK事件

private sub picture1_click()
raiseevent click
end sub

这是LABEL的CLICK事件代码:
private sub label1_click()
call picture1_click()
end sub


为什么会失效啊?
...全文
60 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
mendel 2003-08-28
  • 打赏
  • 举报
回复
谢谢apple200228,结贴~
Apple200228 2003-08-28
  • 打赏
  • 举报
回复
调用方法;
在PictureBox picTop上写字
DrawTheText picTop.hdc, "这是一个测试", 1, rc, 0
Apple200228 2003-08-28
  • 打赏
  • 举报
回复
Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Const CLR_INVALID = -1
Private Const COLOR_HIGHLIGHT = 13
Private Const COLOR_BTNFACE = 15
Private Const COLOR_BTNSHADOW = 16
Private Const COLOR_BTNTEXT = 18
Private Const COLOR_BTNHIGHLIGHT = 20
Private Const COLOR_BTNDKSHADOW = 21
Private Const COLOR_BTNLIGHT = 22
Private Type POINTAPI
x As Long
y As Long
End Type

Public Declare Function DrawText Lib "user32" Alias "DrawTextA" (ByVal hdc As Long, ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long
Public Declare Function SetTextColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long


Public Sub DrawTheText(DestDC As Long, sText As String, iTextLength As Long, rc As RECT, DTF As Long)
'DrawText DestDC, sText, LenB(StrConv(sText, vbFromUnicode)) iTextLength, rc, DTF
DrawText DestDC, sText, LenB(StrConv(sText, vbFromUnicode)), rc, DTF
End Sub

Public Sub SetTheTextColor(DestDC As Long, oColor As OLE_COLOR)
SetTextColor DestDC, oColor
End Sub
mendel 2003-08-27
  • 打赏
  • 举报
回复
高人呢?帮个忙回答了,马上揭贴啊~
mendel 2003-08-27
  • 打赏
  • 举报
回复
帮帮忙啊

关于DRAWTEXT,我在MSN中没有发现啊。
mendel 2003-08-25
  • 打赏
  • 举报
回复
是啊,但是在我这里却有问题啊。
另外,我发现我再在PICTUREBOX中放一个LABEL的话,这个新的LABEL却能检测到CLICK事件,出鬼了。

APPLE200228:能告诉如何使用DRAWTEXT吗?可否给个范例,谢谢。
道素 2003-08-25
  • 打赏
  • 举报
回复
老兄你的代码我试过了没有问题啊
另外你的label是放在picturebox中吧
mendel 2003-08-25
  • 打赏
  • 举报
回复
谢谢,我试一下,好了马上结贴~
Apple200228 2003-08-25
  • 打赏
  • 举报
回复
哦,可以通过Api的Setcapture给控件戴上鼠标跟踪器,就可以检测鼠标的移动了,Caption可以使用函数DrawText来实现。
mendel 2003-08-24
  • 打赏
  • 举报
回复
我在做一个类似于office xp的按钮,现在效果出来了。
也就是可以实现按钮的over和out事件,但是按钮的CAPTION是用的一个LABEL来实现的,我用的是PICTURE控件来检测OVER和OUT事件的,现在PICTURE可以使用,可是当鼠标移到LABEL上的时候,CLICK事件失效,我就想到当LABEL有CLICK事件的时候,调用PICTURE的CLICK事件,但是不成功,单独加上CLICK也不能执行,不知道为什么。
Apple200228 2003-08-24
  • 打赏
  • 举报
回复
你是不是需要添加两个Click,将你的想法告诉我,我帮你看看。
mendel 2003-08-24
  • 打赏
  • 举报
回复
我已经声明过了啊。没用的。
这是我的代码:

Option Explicit
'事件声明:

Private Declare Function SetCapture Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
'Dim disablepicture As Picture

Event Click() 'MappingInfo=Picture1,Picture1,-1,Click
Event DblClick() 'MappingInfo=Picture1,Picture1,-1,DblClick
Event KeyDown(KeyCode As Integer, Shift As Integer) 'MappingInfo=Picture1,Picture1,-1,KeyDown
Event KeyPress(KeyAscii As Integer) 'MappingInfo=Picture1,Picture1,-1,KeyPress
Event KeyUp(KeyCode As Integer, Shift As Integer) 'MappingInfo=Picture1,Picture1,-1,KeyUp
Event MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) 'MappingInfo=Picture1,Picture1,-1,MouseDown
Event MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) 'MappingInfo=Picture1,Picture1,-1,MouseMove
Event MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) 'MappingInfo=Picture1,Picture1,-1,MouseUp
Event Resize() 'MappingInfo=Picture1,Picture1,-1,Resize

Public Enum BackStyleSelection
[透明] = 0
[不透明] = 1
End Enum
Private NewBS As BackStyleSelection

Private Sub Label1_Click()
MsgBox "clicked"
End Sub

Private Sub Picture1_Click()
RaiseEvent Click
End Sub
Apple200228 2003-08-24
  • 打赏
  • 举报
回复
Option Explicit

'事件声明:
Event Click()

Private Sub Label1_Click()
MsgBox "Label1_Click"
RaiseEvent Click
End Sub

Private Sub Picture1_Click()
MsgBox "Picture1_Click"
RaiseEvent Click
End Sub
01 , 01.txt 《 VB6.0通过MSChart控件调用数据库 》 02 , 02.txt 《 用VB6实现动态增减控件 》 03 , 03.txt ActiveX控件的创建 04 , 04.txt ADO控件和DATA控件的冲突(不能共存)的解决方法 05 , 05.txt Combo的自动查询技术 06 , 06.txt DirectX7.0使用心得(1) 07 , 07.txt DirectX7.0使用心得(2) 08 , 08.txt DirectX7.0使用心得(3) 09 , 09.txt FSO对象模型在VB的应用 10 , 10.txt MsComm 控件的文字传输范例 11 , 11.txt Office或IE4风格的ToolBar 12 , 12.txt Regsvr32.exe注册控件的具体用法 13 , 13.txt TextBox的自动调节 14 , 14.txt TextBox实现打印机效果 15 , 15.txt TreeView的基本操作 16 , 16.txt VB5DBGRID控件在VB6使用 17 , 17.txt VB6.0动态加载ActiveX控件漫谈 18 , 18.txt VB与MS-Draw开发通用作图软件 19 , 19.txt VBAPP对象及其应用 20 , 20.txt VBlist控件的功能扩充 21 , 21.txt VB防止将重复项目添加到列表框控件 22 , 22.txt VB用Multimedia MCI控件开发多媒体应用 23 , 23.txt Win Api在VB的妙用 24 , 24.txt WINDOWS SCRIPT HOST对象在VB的使用 25 , 25.txt 安装向导生成程序组并建立多个程序项 26 , 26.txt 保存复选框选项 27 , 27.txt 不用OCX来创建自己的控件(一) 28 , 28.txt 成组更新控件属性 29 , 29.txt 创建数据驱动窗体 30 , 30.txt 得到鼠标位置 31 , 31.txt 调整 Combo 下拉部分的宽度 32 , 32.txt 动态加入控件到VB控件数组 33 , 33.txt 对ListView的列排序 34 , 34.txt 放一个Combo到Toolbar 35 , 35.txt 改变 ListIndex而不发生 Click

1,451

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧