Hi All;
İs there a way for a custom control to add an event running at design time?
for example mouse down or up or move event.
any idea or link acceptable
Printable View
Hi All;
İs there a way for a custom control to add an event running at design time?
for example mouse down or up or move event.
any idea or link acceptable
The cutom control click event is reserved for app runtime only.
If you want to add some more options to your custom control then the best and easiest way of doing so is adding a "PropertyPage" to your control. in the Property Page you can add some more options about your control.
Don't forget to go to your control and in the Property Tab on the side click on the "..." button next to the Property Pages and add your Property Page by checking it. (Default:"PropertyPage1")
If you can't do it like that, this works fine:
For this example, Add 2 labels to your UserControl and a Timer, make you control something like 4 x 4 centimeters, and make your labels a little wider than the default, so you can see messages there dancing at design mode, so the code for your User Control:
Offcourse, compile it, and add it to you VB project.VB Code:
Option Explicit Private Type POINTAPI X As Long Y As Long End Type Private Declare Function WindowFromPoint Lib "user32" _ (ByVal xPoint As Long, _ ByVal yPoint As Long) As Long Private Declare Function RealChildWindowFromPoint Lib "user32" _ (ByVal hWndParent As Long, _ ByVal xPoint As Long, _ ByVal yPoint As Long) As Long Private Declare Function ScreenToClient Lib "user32" _ (ByVal hWnd As Long, _ lpPoint As POINTAPI) As Long Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer Private pa As POINTAPI Public Function GetWindowFromPoint(ByVal X As Long, ByVal Y As Long) As Long Dim p As POINTAPI, ch As Long, h As Long ch = WindowFromPoint(X, Y) Do h = ch p.X = X: p.Y = Y ScreenToClient h, p ch = RealChildWindowFromPoint(h, p.X, p.Y) Loop Until ch = h Or ch = 0 GetWindowFromPoint = h End Function Private Sub UserControl_Initialize() Timer1.Interval = 1 Timer1.Enabled = True End Sub Private Sub Timer1_Timer() GetCursorPos pa If GetWindowFromPoint(pa.X, pa.Y) = UserControl.hWnd Then Label1.Caption = "MouseMove in User Control Area!" 'Mousemove message If CBool(GetAsyncKeyState(vbLeftButton)) Then Label2.Caption = "MouseDown in User Control Area!" 'MouseDown message Else Label2.Caption = "" End If Else Label1.Caption = "" End If End Sub
It should show in design mode..
MouseMove in User Control Area! and..
MouseDown in User Control Area! (when you press left mouse button over it)
Dear jcis;
your example really working, but when at design time control is causing flicker the caption of main VB window and also this feature is also running at run time.
The main reason of my question is to make a control which have two label inside and want labels witdh to adjust with a slider (or something similar) at design time. When mouse pointer is located at near beetwen two labels and pushed LMB we could adjust labels witdh when one is widening other must be narrowed as a classic way
is it possible ?
I'm not sure what you're trying to do. What's LMB? Also, the slider will rezise both labels? Could you show an screenshot?
I'm pretty sure Left Mouse Button.Quote:
Originally Posted by jcis
yes you are right manavo11
LMB is LEFT MOUSE BUTTON every man who deal with PC knows that
dear jcis
what you said "the slider will rezise both labels" is exactly what i want to, i will do much more you want, i attached small VB project and pic.
it maybe show you the main idea that i want
this is a project i started but not finished yet unfortunately.
dear jcis
did you review my small project? I wonder what you will say.