473,795 Members | 2,967 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Get name of control at a certain mousedown point

I have several labels and textboxes that are drawn to a tab page based on
certain criteria so these labels and textboxes can be drawn at different
points on the tab page. I set the label and textbox names in the drawing
procedure. Now what I need to do is to get the control's information on a
mouse down.

Here is what I have:

////
Private Sub tcGuard_MouseDo wn(ByVal sender as Object, ByVal e as
System.Windows. Forms.MouseEven tArgs) Handles tcGuard.Mousedo wn 'tcGuard is
a tab control
Dim mouseLocale as new point(e.X, e.Y)
dim tName as String
dim cntrl as New Control
cntrl = tcGuard.GetChil dAtPoint(mouseL ocale)
tname = cntrl.Name
End Sub
\\\\

Here is the error message I get: Object reference not set to an instance of
an object.

All I need to do at this juncture is get the name of the label or textbox
that the mouse clicked on.

If I am doing this wrong, please let me know and thanks for any help you can
give.

Brad
Nov 21 '05 #1
7 6786
The mouse event's will be handled by the individual controls so you'll need
to wire all the controls click events up to a handler in the tab page or tab
control.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Brad" <ba******@ukcdo gs.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
I have several labels and textboxes that are drawn to a tab page based on
certain criteria so these labels and textboxes can be drawn at different
points on the tab page. I set the label and textbox names in the drawing
procedure. Now what I need to do is to get the control's information on a
mouse down.

Here is what I have:

////
Private Sub tcGuard_MouseDo wn(ByVal sender as Object, ByVal e as
System.Windows. Forms.MouseEven tArgs) Handles tcGuard.Mousedo wn 'tcGuard
is a tab control
Dim mouseLocale as new point(e.X, e.Y)
dim tName as String
dim cntrl as New Control
cntrl = tcGuard.GetChil dAtPoint(mouseL ocale)
tname = cntrl.Name
End Sub
\\\\

Here is the error message I get: Object reference not set to an instance
of an object.

All I need to do at this juncture is get the name of the label or textbox
that the mouse clicked on.

If I am doing this wrong, please let me know and thanks for any help you
can give.

Brad

Nov 21 '05 #2
Bob,

Thanks for that information. Being fairly new to .Net, I do understand when
you talk about the handler event in the tab page or tab control. But if I
do not know what labels or textboxes will be drawn on the tabpage, how would
I add a handler? I guess I am not understanding that part and that is why I
am trying to get the control's name based on the point of the MouseDown
event.

Brad
"Bob Powell [MVP]" <bob@_spamkille r_bobpowell.net > wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
The mouse event's will be handled by the individual controls so you'll
need to wire all the controls click events up to a handler in the tab page
or tab control.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Brad" <ba******@ukcdo gs.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
I have several labels and textboxes that are drawn to a tab page based on
certain criteria so these labels and textboxes can be drawn at different
points on the tab page. I set the label and textbox names in the drawing
procedure. Now what I need to do is to get the control's information on a
mouse down.

Here is what I have:

////
Private Sub tcGuard_MouseDo wn(ByVal sender as Object, ByVal e as
System.Windows. Forms.MouseEven tArgs) Handles tcGuard.Mousedo wn 'tcGuard
is a tab control
Dim mouseLocale as new point(e.X, e.Y)
dim tName as String
dim cntrl as New Control
cntrl = tcGuard.GetChil dAtPoint(mouseL ocale)
tname = cntrl.Name
End Sub
\\\\

Here is the error message I get: Object reference not set to an instance
of an object.

All I need to do at this juncture is get the name of the label or textbox
that the mouse clicked on.

If I am doing this wrong, please let me know and thanks for any help you
can give.

Brad


Nov 21 '05 #3
Brad,

In addition to Bob.

However when you want to know what type the object is and know it derives
from control than you can do something as

\\\
Private Sub Button1_Click(B yVal sender As System.Object, _
ByVal e As System.EventArg s) Handles Button1.Click
If TypeOf sender Is Button Then
MessageBox.Show ("I am a Button")
MessageBox.Show _
("My name is " & DirectCast(send er, Control).Name)
End If
End Sub
///
To show your 2 solutions in one sample.

I hope this helps,

Cor
Nov 21 '05 #4
Brad,

I found it as well a little bit confusing what Bob wrote in that part,
however I think that he means to create one event sub and add to that using
the clasic VB method in
\\\\
Private Sub MyClick(ByVal sender As System.Object, _
ByVal e As System.EventArg s) Handles Button1.Click, Label1.Click, etc
///
See the end of above
or
\\\
AddHandler Button1.Click, AddressOf MyClick
///
The last you can do as well in a loop for all the controls which should have
when you see the sample I sent as well in this thread.

You can think about
\\\
For each ctr as control in tabpage.control s
AddHandler ctr.Click, AddressOf MyClick
next
///

All controls have a click event and more in common
http://msdn.microsoft.com/library/de...mberstopic.asp

I hope this helps?

Cor
Nov 21 '05 #5
Cor,

I am still confused. I have a tab control with 8 pages that are set.
Within those 8 pages are 8 more tab controls that are drawn on. Within
those drawn tab pages is where the labels and textboxes are drawn. All of
this is driven based on criteria of data that is pulled from a SQL database.

I can easily reference the original 8 tap pages from the main tab control,
but if one wants to click on a sub page and then click on one of the labels
or text boxes in this page, this is where I need an event (a drag and drop)
to occur.

I certainly cannot build "Private Sub....Handles Label1.Click because Label1
may or may not be there.

My thinking was on the mouse down event of the tab page, get the XY
coordinates and then based on the tab page, get the control at that
location.

Complicated, I know. But learning the language myself, I have had to tackle
these issues and once I do, I remember from there on.

Brad

"Cor Ligthert" <no************ @planet.nl> wrote in message
news:eW******** ******@TK2MSFTN GP14.phx.gbl...
Brad,

I found it as well a little bit confusing what Bob wrote in that part,
however I think that he means to create one event sub and add to that using the clasic VB method in
\\\\
Private Sub MyClick(ByVal sender As System.Object, _
ByVal e As System.EventArg s) Handles Button1.Click, Label1.Click, etc
///
See the end of above
or
\\\
AddHandler Button1.Click, AddressOf MyClick
///
The last you can do as well in a loop for all the controls which should have when you see the sample I sent as well in this thread.

You can think about
\\\
For each ctr as control in tabpage.control s
AddHandler ctr.Click, AddressOf MyClick
next
///

All controls have a click event and more in common
http://msdn.microsoft.com/library/de...mberstopic.asp
I hope this helps?

Cor

Nov 21 '05 #6
It looks as if you should programmaticall y step through the Control lists of
the nested items and use AddHandler to grab the mousemove or click events of
the various nested components.

The trouble is that if the mouse is inside say a textbox control the tabpage
will never see the mousedown because it will be handled by the textbox. This
is why you should ensure that a particular handler converts the current
mouse position to fit the context of whichever control you treat as the
parent.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"AllcompPC" <al*******@sbcg lobal.net> wrote in message
news:Oe******** ******@TK2MSFTN GP14.phx.gbl...
Cor,

I am still confused. I have a tab control with 8 pages that are set.
Within those 8 pages are 8 more tab controls that are drawn on. Within
those drawn tab pages is where the labels and textboxes are drawn. All of
this is driven based on criteria of data that is pulled from a SQL
database.

I can easily reference the original 8 tap pages from the main tab control,
but if one wants to click on a sub page and then click on one of the
labels
or text boxes in this page, this is where I need an event (a drag and
drop)
to occur.

I certainly cannot build "Private Sub....Handles Label1.Click because
Label1
may or may not be there.

My thinking was on the mouse down event of the tab page, get the XY
coordinates and then based on the tab page, get the control at that
location.

Complicated, I know. But learning the language myself, I have had to
tackle
these issues and once I do, I remember from there on.

Brad

"Cor Ligthert" <no************ @planet.nl> wrote in message
news:eW******** ******@TK2MSFTN GP14.phx.gbl...
Brad,

I found it as well a little bit confusing what Bob wrote in that part,
however I think that he means to create one event sub and add to that

using
the clasic VB method in
\\\\
Private Sub MyClick(ByVal sender As System.Object, _
ByVal e As System.EventArg s) Handles Button1.Click, Label1.Click, etc
///
See the end of above
or
\\\
AddHandler Button1.Click, AddressOf MyClick
///
The last you can do as well in a loop for all the controls which should

have
when you see the sample I sent as well in this thread.

You can think about
\\\
For each ctr as control in tabpage.control s
AddHandler ctr.Click, AddressOf MyClick
next
///

All controls have a click event and more in common

http://msdn.microsoft.com/library/de...mberstopic.asp

I hope this helps?

Cor


Nov 21 '05 #7
Cor and Bob,

Thank you for your help. It is now working to what I want it to do. I used
the AddHandler statements - one for DragEnter and one for DragDrop in the
same routine that draws the label to the tab page.

Brad
"Brad" <ba******@ukcdo gs.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
I have several labels and textboxes that are drawn to a tab page based on
certain criteria so these labels and textboxes can be drawn at different
points on the tab page. I set the label and textbox names in the drawing
procedure. Now what I need to do is to get the control's information on a
mouse down.

Here is what I have:

////
Private Sub tcGuard_MouseDo wn(ByVal sender as Object, ByVal e as
System.Windows. Forms.MouseEven tArgs) Handles tcGuard.Mousedo wn 'tcGuard is a tab control
Dim mouseLocale as new point(e.X, e.Y)
dim tName as String
dim cntrl as New Control
cntrl = tcGuard.GetChil dAtPoint(mouseL ocale)
tname = cntrl.Name
End Sub
\\\\

Here is the error message I get: Object reference not set to an instance of an object.

All I need to do at this juncture is get the name of the label or textbox
that the mouse clicked on.

If I am doing this wrong, please let me know and thanks for any help you can give.

Brad

Nov 21 '05 #8

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

Similar topics

2
1318
by: Jim Hubbard | last post by:
I am searching for code that will show me how to monitor WAPs and connect/disconnect from them programmatically. Anybody seen this stuff?
5
3882
by: Brian Rypstra | last post by:
Does any one know if there exists a form control that can function much like a rectangle control but is circular (or 6 sided say)? Can I make a custom control called circle that groups 6 instances of the line control and functions exactly like the line control (props, events etc) . I think I can do it with net but don't want to learn it, hopefully I can do it with access or VBA Please help steer me in the right direction Thanks
3
6832
by: MikeY | last post by:
Hi Everyone, I am working in C#, windows forms.My question is this. All my button dynamic controls properties are present and accounted for except for the"FlatStyle" properties. I can't seem to figure out, if there is a way of using polymorphic way (if that is a word) of doing this particular property. A sample of my code is as follows: DynamicControls.ButtonControl(this,btnSearchByName, new Point(5, 75), new Size(95, 20),...
2
5203
by: fragget | last post by:
hi- i have a custom control that can be dragged onto a form. the control can be dragged around the form with the mouse. i want to draw a selection box around my control when it is selected to be dragged. on the mouse down event of my control i want to pass the size of the control and the location to the parent so that i can draw a selection box around it.
4
3348
by: gsb58 | last post by:
Hi! On a form I have a calendar. The form is rezised to 1024x768 (Don't worry - this is a training case) when loaded. Now I want to center the calendar on the form so that its edges are equally far from the upper, right, left and bottom borders of the form. I understand I must use the location property, am I right?
0
970
by: baerland | last post by:
Hi all, Got a strange issue here: By using the upload control and browsing to a certain file, my btnUpload_click event wont fire. Other files are uploaded without problems. The acl settings are the same for all files, but this one file, on selection via browse, breaks the server side processing.
3
1789
by: Dodong | last post by:
I am new to vb6 programming. I would like to know the code on how to change the menu name control properties at run time. For example I want to disable visibility of File/open when a certain condition exists.
2
1327
by: =?Utf-8?B?SHVzYW0=?= | last post by:
Hi EveryBody: My question Is how can I control or track any Ip of computer and prevent it from entering web site either by domain name or ite IP address For example: If my computer IP is 10.0.0.117 and Domain name for site is www.yahoo.com and its relevent IP address id for example 84.34.55.213 how can I control the first IP to not enter a second IP ?
1
26545
GaryTexmo
by: GaryTexmo | last post by:
In my last insight, http://bytes.com/topic/c-sharp/insights/909141-object-scaling-varying-resolutions, I talked about scaling objects to a form's size so that it would always draw with the correct scale. In that, the method I used to create and store objects that could be drawn on my form was a manual approach; that is, I created and stored a list of objects, then manually drew them. While that certainly works, it means there's a lot of code...
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10436
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10163
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9040
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6780
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3722
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.