473,386 Members | 1,720 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,386 software developers and data experts.

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_MouseDown(ByVal sender as Object, ByVal e as
System.Windows.Forms.MouseEventArgs) Handles tcGuard.Mousedown '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.GetChildAtPoint(mouseLocale)
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 6744
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******@ukcdogs.com> wrote in message
news:%2****************@TK2MSFTNGP12.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_MouseDown(ByVal sender as Object, ByVal e as
System.Windows.Forms.MouseEventArgs) Handles tcGuard.Mousedown '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.GetChildAtPoint(mouseLocale)
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@_spamkiller_bobpowell.net> wrote in message
news:%2****************@tk2msftngp13.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******@ukcdogs.com> wrote in message
news:%2****************@TK2MSFTNGP12.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_MouseDown(ByVal sender as Object, ByVal e as
System.Windows.Forms.MouseEventArgs) Handles tcGuard.Mousedown '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.GetChildAtPoint(mouseLocale)
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(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
If TypeOf sender Is Button Then
MessageBox.Show("I am a Button")
MessageBox.Show _
("My name is " & DirectCast(sender, 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.EventArgs) 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.controls
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**************@TK2MSFTNGP14.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.EventArgs) 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.controls
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 programmatically 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*******@sbcglobal.net> wrote in message
news:Oe**************@TK2MSFTNGP14.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**************@TK2MSFTNGP14.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.EventArgs) 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.controls
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******@ukcdogs.com> wrote in message
news:%2****************@TK2MSFTNGP12.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_MouseDown(ByVal sender as Object, ByVal e as
System.Windows.Forms.MouseEventArgs) Handles tcGuard.Mousedown '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.GetChildAtPoint(mouseLocale)
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
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
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...
3
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...
2
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...
4
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...
0
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...
3
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...
2
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...
1
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.