473,414 Members | 1,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

How to select a region on a form

I am trying to build a daily calendar similar to Microsoft Outlook where a
user can select hours of a day using mouse. I have a form that holds a
panel which contains user controls each representing an hour of the day (24
hours = 24 user controls).

How can I mouse-down, drag, mouse-up select a region (say from 9:00am to
1:00pm)?

I was trying to use mouse down/mouse up events and return the tag property
of the user controls on down / up but even though I drag with the mouse over
several controls, both of these events return tag property of the user
control that received mouse down event.

Any help will be greatfully appreciated
Dino

--
-------------------------------------------------------------------------
FIGHT BACK AGAINST SPAM!
Download Spam Inspector, the Award Winning Anti-Spam Filter
http://mail.giantcompany.com

Nov 20 '05 #1
5 1430
On Thu, 27 Nov 2003 16:35:18 GMT, "Dino M. Buljubasic"
<di*************@rivusglobal.com> wrote:
I am trying to build a daily calendar similar to Microsoft Outlook where a
user can select hours of a day using mouse. I have a form that holds a
panel which contains user controls each representing an hour of the day (24
hours = 24 user controls).

How can I mouse-down, drag, mouse-up select a region (say from 9:00am to
1:00pm)?

I was trying to use mouse down/mouse up events and return the tag property
of the user controls on down / up but even though I drag with the mouse over
several controls, both of these events return tag property of the user
control that received mouse down event.

Any help will be greatfully appreciated
Dino


I had a similar problem. This is how I solved it:
1) Catch MouseDown, MouseMove and MouseUp in the user control.
2) Implement a static function that finds the user control located at
a particular point.

e.g.
Private Shared GetControlAt(mousePoint As Point) _
As MyUserContol

3) Implement a class that contains the rectangle being selected (top
-left and bottom-right points - initial mouse down and current mouse
position).

This enables you to redirect MouseMove events (which will be initially
received by the same control you did the mouse down on) to the
appropriate control, if needs be. Therein, you can test to see if it
is in the selected region.
So, in each of the mouse events, the first check should be to see that
the mouse pointer is in the current control. If it is not, redirect
the event to the proper control. If it is, do your selection test
and/or selection size adjustment.

i.e.
...MouseMove...
MyUserControl ctrl = GetControlAt( mouseLocation )
If ctrl Is Me Then
' Do the selection, or whatever
ElseIf Not ctrl Is Nothing Then
' Redirect this to the proper control
ctrl_MouseMove...
End If
hth

Andy

Nov 20 '05 #2
Hi Andy,

thanks for reading this post and for your reply. The only thing I don't
understand is how to redirect mouse move event to another control. Can you
explain me that?

Thank you,
Dino

--
-------------------------------------------------------------------------
FIGHT BACK AGAINST SPAM!
Download Spam Inspector, the Award Winning Anti-Spam Filter
http://mail.giantcompany.com
"_Andy_" <wi******@nospamthanks.gov> wrote in message
news:ch********************************@4ax.com...
On Thu, 27 Nov 2003 16:35:18 GMT, "Dino M. Buljubasic"
<di*************@rivusglobal.com> wrote:
I am trying to build a daily calendar similar to Microsoft Outlook where auser can select hours of a day using mouse. I have a form that holds a
panel which contains user controls each representing an hour of the day (24hours = 24 user controls).

How can I mouse-down, drag, mouse-up select a region (say from 9:00am to
1:00pm)?

I was trying to use mouse down/mouse up events and return the tag propertyof the user controls on down / up but even though I drag with the mouse overseveral controls, both of these events return tag property of the user
control that received mouse down event.

Any help will be greatfully appreciated
Dino


I had a similar problem. This is how I solved it:
1) Catch MouseDown, MouseMove and MouseUp in the user control.
2) Implement a static function that finds the user control located at
a particular point.

e.g.
Private Shared GetControlAt(mousePoint As Point) _
As MyUserContol

3) Implement a class that contains the rectangle being selected (top
-left and bottom-right points - initial mouse down and current mouse
position).

This enables you to redirect MouseMove events (which will be initially
received by the same control you did the mouse down on) to the
appropriate control, if needs be. Therein, you can test to see if it
is in the selected region.
So, in each of the mouse events, the first check should be to see that
the mouse pointer is in the current control. If it is not, redirect
the event to the proper control. If it is, do your selection test
and/or selection size adjustment.

i.e.
...MouseMove...
MyUserControl ctrl = GetControlAt( mouseLocation )
If ctrl Is Me Then
' Do the selection, or whatever
ElseIf Not ctrl Is Nothing Then
' Redirect this to the proper control
ctrl_MouseMove...
End If
hth

Andy

Nov 20 '05 #3
On Thu, 27 Nov 2003 18:36:49 GMT, "Dino M. Buljubasic"
<di*************@rivusglobal.com> wrote:
Hi Andy,

thanks for reading this post and for your reply. The only thing I don't
understand is how to redirect mouse move event to another control. Can you
explain me that?

Thank you,
Dino


By "redirection" I simply meant the act of calling the handler of
another instance of the class (instead of this one itself). It's taken
care of by the "If ctrl Is Me Then" line. The logic is this:

If the mouse pointer is within the rectangle of this control
Handle the event
Else
Find the control that is under the pointer
Call the handler of that control instead
End If

What I did fail to mention is the use of "Form.GetChildAtPoint()" to
determine which control the mouse is over.

hth

Nov 20 '05 #4
thanks Andy :)

--
-------------------------------------------------------------------------
FIGHT BACK AGAINST SPAM!
Download Spam Inspector, the Award Winning Anti-Spam Filter
http://mail.giantcompany.com
"_Andy_" <wi******@nospamthanks.gov> wrote in message
news:0p********************************@4ax.com...
On Thu, 27 Nov 2003 18:36:49 GMT, "Dino M. Buljubasic"
<di*************@rivusglobal.com> wrote:
Hi Andy,

thanks for reading this post and for your reply. The only thing I don't
understand is how to redirect mouse move event to another control. Can youexplain me that?

Thank you,
Dino


By "redirection" I simply meant the act of calling the handler of
another instance of the class (instead of this one itself). It's taken
care of by the "If ctrl Is Me Then" line. The logic is this:

If the mouse pointer is within the rectangle of this control
Handle the event
Else
Find the control that is under the pointer
Call the handler of that control instead
End If

What I did fail to mention is the use of "Form.GetChildAtPoint()" to
determine which control the mouse is over.

hth

Nov 20 '05 #5
Hi Andy,

sorry for annoying you :) but I have a problem that I can not solve and was
hoping you could help me with that.

I am trying to get coordinates of mouse_down/mouse_up event BUT relevant to
the form or the parent of a control, not to the control where mouse click
has occured. That means, even if I click a control on the form, I want to
get the coordinates of the form of the click event, not coordinates of the
control that was clicked on.

My user controls are on a panel pnToday. Each user control has two text
boxes inside representing whole and half hour (e.g. 11:00 am and 11:30am)
Currently I am doint it as:

' add event handler to all dynamically loaded user controls
AddHandler ctype(MyUserControl.TextBox1, TextBox).MouseDown, AddressOf
pnToday_MouseDown
AddHandler ctype(MyUserControl.TextBox2, TextBox).MouseDown, AddressOf
pnToday_MouseDown
AddHandler ctype(MyUserControl.TextBox1, TextBox).MouseUp, AddressOf
pnToday_MouseUp
AddHandler ctype(MyUserControl.TextBox2, TextBox).MouseUp, AddressOf
pnToday_MouseUp

' then in my mouse down / up events for the panel (parent of user controls)
Private Sub pnToday_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles pnToday.MouseDown
ptEntryPoint = New Point(e.X, e.Y)
EntryTextBox = Me.GetChildAtPoint(ptEntryPoint)
'MsgBox(EntryTextBox.GetType.ToString) ' this should retrun type of
control clicked but it returns type of my toolbar
End Sub

Private Sub pnToday_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles pnToday.MouseUp
ptExitPoint = New Point(e.X, e.Y)

ExitTextBox = Me.GetChildAtPoint(ptExitPoint)

MsgBox("Entry at (" & ptEntryPoint.X & " ; " & ptEntryPoint.Y & ")"
& vbCrLf & _
"Exit at (" & ptExitPoint.X & " ; " & ptExitPoint.Y & ")")

MsgBox("Entry Hour: " & CType(EntryTextBox, TextBox).Tag & " " &
" Exit Hour: " & CType(ExitTextBox, TextBox).Tag) ' this crashes because of
invalid type conversion from toolbar to textbox, because the point returned
is not relevant to parent container of user controls.
End Sub

Regards,
Dino

--
-------------------------------------------------------------------------
FIGHT BACK AGAINST SPAM!
Download Spam Inspector, the Award Winning Anti-Spam Filter
http://mail.giantcompany.com
"_Andy_" <wi******@nospamthanks.gov> wrote in message
news:0p********************************@4ax.com...
On Thu, 27 Nov 2003 18:36:49 GMT, "Dino M. Buljubasic"
<di*************@rivusglobal.com> wrote:
Hi Andy,

thanks for reading this post and for your reply. The only thing I don't
understand is how to redirect mouse move event to another control. Can youexplain me that?

Thank you,
Dino


By "redirection" I simply meant the act of calling the handler of
another instance of the class (instead of this one itself). It's taken
care of by the "If ctrl Is Me Then" line. The logic is this:

If the mouse pointer is within the rectangle of this control
Handle the event
Else
Find the control that is under the pointer
Call the handler of that control instead
End If

What I did fail to mention is the use of "Form.GetChildAtPoint()" to
determine which control the mouse is over.

hth

Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mad Scientist Jr | last post by:
I'm trying to get javascipt select all items in a HTML form <SELECT> control and submit the form to an asp.net page. For some reason when the link is clicked, you can see the items all get...
11
by: Altramagnus | last post by:
I have a complicated Region object, which I need to draw the outline, but not fill How can I convert the Region object to GraphicsPath object? or How can I draw the outline of the Region object?
18
by: CJM | last post by:
I'm building a search function for one of my applications. The user has the option to enter a number criteria of criteria, but none are compulsary. I need to be able to build up a query string that...
1
by: jtwright | last post by:
I've got a view that creates a parent child relationship, this view is used in Analysis Services to create a dimension in a datastore. This query tends to deadlock after about 10 days of running...
1
by: Neil H | last post by:
Hi All I am doing a multiple table and field database search, and my problem lies in the options that a user has. In each field, the user can specify a specific value or any value. I take each...
2
by: M West | last post by:
hello, currently trying to write a custom control that will display an image in true transparent form, e.g. can actually see the background images placed behind the control rather than the...
3
by: mso5 | last post by:
Hi, I am trying to build a small form with a list of countries and regions by each country (yes, the classical one), and I'm stuck with it. I'm using AJAX also, and I manage to get the correct...
2
by: Sudhakar | last post by:
i have two select tags as part of a registration form, city1 city2 where city1 has a list of regions and similar for city2 there are different regions for city1 and city2 so instead of all the...
72
by: viki1967 | last post by:
Hi everyone. Help with this problem. With Google I found this script: var regiondb = new Object() regiondb = ;
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.