|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
some general mouse events should be therehi everyone,
i m having a problem with mouse events. any help related is apreciated. i m having a form in which i m having 2 buttons. and i m moving(draging) these buttons on run time using mousemove event handler but i m having same code in side two mousedown for two buttons. so i want to know is there a way to find out which control is selected on mousedown and then call only one generic function for 2 button which will handle draging. thanks sagar sagar wrote:
> so i want to know is there a way to find out which control is selected Yes, the sender parameter in your mouse event handler is the object> on mousedown and then call only one generic function for 2 button which > will handle draging. that raised the event. You can use that to determine which button was clicked. Chris Dunaway wrote:
> sagar wrote: thanks for the reply.> > > so i want to know is there a way to find out which control is selected > > on mousedown and then call only one generic function for 2 button which > > will handle draging. > > Yes, the sender parameter in your mouse event handler is the object > that raised the event. You can use that to determine which button was > clicked. but the problem is, i m using OnMouseDown() event which is raised when i clicks on form when i clicks on button1 then button1_mousedown(..) is raised. no general mousedown function is there which is called for every mousedown either on form or on controls and from there i can find out where i have clicked. sagar wrote:
Show quoteHide quote > Chris Dunaway wrote: So in other words, you are using the mouse to select a control on the> > > sagar wrote: > > > > > so i want to know is there a way to find out which control is selected > > > on mousedown and then call only one generic function for 2 button which > > > will handle draging. > > > > Yes, the sender parameter in your mouse event handler is the object > > that raised the event. You can use that to determine which button was > > clicked. > > thanks for the reply. > but the problem is, i m using OnMouseDown() event which is raised when > i clicks on form when i clicks on button1 then button1_mousedown(..) is > raised. no general mousedown function is there which is called for > every mousedown either on form or on controls and from there i can find > out where i have clicked. form, such as a button, and you then want to move that control by dragging it somewhere else on the form. So you need to know how to determine which control has been clicked. I'm not sure I know how to help you. You could possibly get the x,y coordinates of the mouse click and then loop through the controls on your form and find out if that point is withing the area taken up by your control. Perhaps someone else will be able to suggest a better approach. Sorry yes,
i m doing the same thing u pointed out i got the collection of all controls on a form but i m abe to find the location on which i have clicked. thanks any ways for ur attention sorry if i m not clear in my question thanks yes,
i m doing the same thing u pointed out i got the collection of all controls on a form but i m not abe to find the location on which i have clicked. thanks any ways for ur attention sorry if i m not clear in my question thanks sagar wrote:
> yes, To get the current location of the mouse, you can try using> i m doing the same thing u pointed out > i got the collection of all controls on a form but i m not abe to find > the > location on which i have clicked. > > thanks any ways for ur attention > sorry if i m not clear in my question > > thanks Cursor.Current.Position. You may have to convert those coordinates from Scren coordinates to Client coordinates using Control.PointToClient. sorry for late reply
yes u r right i have to get the location of mouse down but how i mean there is form_mousedown() fuction which get called when mouse button is down on form but not when down on any control and control_mousedown() get called when mouse button is down on that perticular control not on any other control or form solution should be like a comman mousedown which will get called on every mouse down,i think there should be some api function which first get called on every mouse down and then this functions calls our applications form or control _mousedown function i ll be thankful to u if u help me solving this i hav searched a lot on this and spend lot of time too but still not able to find solution thanks sagar sagar wrote:
> sorry for late reply Do you mean for any application that is running? Or just in any form> > yes u r right i have to get the location of mouse down but how > i mean there is form_mousedown() fuction which get called when mouse > button is down on form but not when down on any control and > control_mousedown() get called when mouse button is down on that > perticular control not on any other control or form or control in your own application? For system wide detection of the mouse, do a search for Mouse Hooks. You can implement a mouse hook to capture mouse activity system wide. For just your own application, look into using the NativeWindow class. Try these links: http://www.vbaccelerator.com/home/NET/Code/Libraries/Windows_Messages/Subclassing_in__NET/article.asp http://www2.sys-con.com/ITSG/virtualcd/Dotnet/archives/0112/hankins/index.html hi chris,
i m looking the links u send, i think it ll solve the problem thanks a lot sagar hi chris,
i have used wndproc to get the left mousedown event like this (copy this code in the form1.vb as it is) ************** code starts ******************** Imports System Imports System.Drawing Imports System.Windows.Forms Public Class Form1 Inherits System.Windows.Forms.Form ' Constant value was found in the "windows.h" header file. Private Const WM_LBUTTONDOWN As Integer = &H201 Private Const WM_NCLBUTTONDOWN As Integer = &HA1 <STAThread()> _ Shared Sub Main() Application.Run(New Form1) End Sub 'Main Public Sub New() MyBase.New() InitializeComponent() End Sub <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _ Protected Overrides Sub WndProc(ByRef m As Message) ' Listen for operating system messages Select Case (m.Msg) Case WM_LBUTTONDOWN MsgBox(Control.MousePosition.ToString()) Case Else MyBase.WndProc(m) End Select MyBase.WndProc(m) End Sub Friend WithEvents Button1 As System.Windows.Forms.Button Friend WithEvents TextBox1 As System.Windows.Forms.TextBox Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents Button2 As System.Windows.Forms.Button Private Sub InitializeComponent() Me.Button1 = New System.Windows.Forms.Button Me.TextBox1 = New System.Windows.Forms.TextBox Me.Label1 = New System.Windows.Forms.Label Me.Button2 = New System.Windows.Forms.Button Me.SuspendLayout() ' 'Button1 ' Me.Button1.Location = New System.Drawing.Point(72, 88) Me.Button1.Name = "Button1" Me.Button1.Size = New System.Drawing.Size(72, 32) Me.Button1.TabIndex = 0 Me.Button1.Text = "Button1" ' 'TextBox1 ' Me.TextBox1.Location = New System.Drawing.Point(56, 160) Me.TextBox1.Name = "TextBox1" Me.TextBox1.Size = New System.Drawing.Size(184, 20) Me.TextBox1.TabIndex = 1 Me.TextBox1.Text = "TextBox1" ' 'Label1 ' Me.Label1.Location = New System.Drawing.Point(40, 32) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(192, 16) Me.Label1.TabIndex = 2 Me.Label1.Text = "Label1" ' 'Button2 ' Me.Button2.Location = New System.Drawing.Point(88, 216) Me.Button2.Name = "Button2" Me.Button2.Size = New System.Drawing.Size(88, 24) Me.Button2.TabIndex = 3 Me.Button2.Text = "Button2" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(292, 273) Me.Controls.Add(Me.Button2) Me.Controls.Add(Me.Label1) Me.Controls.Add(Me.TextBox1) Me.Controls.Add(Me.Button1) Me.Name = "Form1" Me.ResumeLayout(False) End Sub Private Sub Button1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown MsgBox("button1_down" & " " & x.ToString & " " & y.ToString) End Sub Private Sub Button1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown MsgBox("button1_up" & " " & x.ToString & " " & y.ToString) End Sub End Class ****************** code ends *************** the problem with this is that 1) it also working for left mousedown in non-client area which i dont want and 2) after left mousedown on any control(eg. for button1) Button1_mousedown() should also get called which is not happening pl. have a look at it thanks sagar |
|||||||||||||||||||||||