Location of a form opened by an instance of a custom control [duplicate]











up vote
-1
down vote

favorite













This question already has an answer here:




  • Getting The Location Of A Control Relative To The Entire Screen?

    1 answer



  • How to get exact position of a panel or picturebox?

    1 answer




I have designed a custom control with a picturebox, to which a click event is associated that opens a dialogbox form:



    Private Sub pbCalendarClockSettings_Click(sender As Object, e As EventArgs) Handles pbCalendarClockSettings.Click
Dim myform As New frmCalendarClockSettings
myform.StartPosition = FormStartPosition.Manual
myform.Location = New Point(Me.Location.X, Me.Location.Y)
...


I'd like the form to open at location point of the instance of the custom control and that's what this line is supposed to do.



myform.Location = New Point(Me.Location.X, Me.Location.Y)


Unfortunately, when I instance the custom control in an application, Me.location does not seem to be the location of the instance (is offset to the top of the screen).
The custom control can be instantiated at design time and/or run time.



How do I point to the instance location in the custom control code?










share|improve this question













marked as duplicate by Visual Vincent, Jimi, IvanH, WelcomeOverflow vb.net
Users with the  vb.net badge can single-handedly close vb.net questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 23 at 0:44


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • ...or actually, even better: Getting The Location Of A Control Relative To The Entire Screen?
    – Visual Vincent
    Nov 22 at 17:24










  • It's not a duplicate. Point location = someControl.PointToScreen(Point.Empty) requires you to know the name of the instance of the custom control. My case is different: the instance of the custom control needs to know its own position.
    – Alessandro Mandelli
    Nov 22 at 18:07








  • 2




    All controls are aware of their own positions. If you need to get the screen coordinates from within the control itself just replace the name with Me, like so: Dim Location As Point = Me.PointToScreen(Point.Empty) - it works the same way as when you use Me inside a form.
    – Visual Vincent
    Nov 22 at 19:06












  • PointToScreen() is a member of all controls so you don't necessarily need to know the name of which one to target, all you need is an instance (Me refers to the current instance).
    – Visual Vincent
    Nov 22 at 19:11








  • 1




    No, you don't need to know the name of the instance. You need to have a reference to the instance. A variable that refers to an object is not the name of the object. As suggested, every object can refer to itself using Me. You're even already doing that in the code you posted so you already know that. This is a case of having two bits of information but not putting them together.
    – jmcilhinney
    Nov 22 at 22:48















up vote
-1
down vote

favorite













This question already has an answer here:




  • Getting The Location Of A Control Relative To The Entire Screen?

    1 answer



  • How to get exact position of a panel or picturebox?

    1 answer




I have designed a custom control with a picturebox, to which a click event is associated that opens a dialogbox form:



    Private Sub pbCalendarClockSettings_Click(sender As Object, e As EventArgs) Handles pbCalendarClockSettings.Click
Dim myform As New frmCalendarClockSettings
myform.StartPosition = FormStartPosition.Manual
myform.Location = New Point(Me.Location.X, Me.Location.Y)
...


I'd like the form to open at location point of the instance of the custom control and that's what this line is supposed to do.



myform.Location = New Point(Me.Location.X, Me.Location.Y)


Unfortunately, when I instance the custom control in an application, Me.location does not seem to be the location of the instance (is offset to the top of the screen).
The custom control can be instantiated at design time and/or run time.



How do I point to the instance location in the custom control code?










share|improve this question













marked as duplicate by Visual Vincent, Jimi, IvanH, WelcomeOverflow vb.net
Users with the  vb.net badge can single-handedly close vb.net questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 23 at 0:44


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • ...or actually, even better: Getting The Location Of A Control Relative To The Entire Screen?
    – Visual Vincent
    Nov 22 at 17:24










  • It's not a duplicate. Point location = someControl.PointToScreen(Point.Empty) requires you to know the name of the instance of the custom control. My case is different: the instance of the custom control needs to know its own position.
    – Alessandro Mandelli
    Nov 22 at 18:07








  • 2




    All controls are aware of their own positions. If you need to get the screen coordinates from within the control itself just replace the name with Me, like so: Dim Location As Point = Me.PointToScreen(Point.Empty) - it works the same way as when you use Me inside a form.
    – Visual Vincent
    Nov 22 at 19:06












  • PointToScreen() is a member of all controls so you don't necessarily need to know the name of which one to target, all you need is an instance (Me refers to the current instance).
    – Visual Vincent
    Nov 22 at 19:11








  • 1




    No, you don't need to know the name of the instance. You need to have a reference to the instance. A variable that refers to an object is not the name of the object. As suggested, every object can refer to itself using Me. You're even already doing that in the code you posted so you already know that. This is a case of having two bits of information but not putting them together.
    – jmcilhinney
    Nov 22 at 22:48













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite












This question already has an answer here:




  • Getting The Location Of A Control Relative To The Entire Screen?

    1 answer



  • How to get exact position of a panel or picturebox?

    1 answer




I have designed a custom control with a picturebox, to which a click event is associated that opens a dialogbox form:



    Private Sub pbCalendarClockSettings_Click(sender As Object, e As EventArgs) Handles pbCalendarClockSettings.Click
Dim myform As New frmCalendarClockSettings
myform.StartPosition = FormStartPosition.Manual
myform.Location = New Point(Me.Location.X, Me.Location.Y)
...


I'd like the form to open at location point of the instance of the custom control and that's what this line is supposed to do.



myform.Location = New Point(Me.Location.X, Me.Location.Y)


Unfortunately, when I instance the custom control in an application, Me.location does not seem to be the location of the instance (is offset to the top of the screen).
The custom control can be instantiated at design time and/or run time.



How do I point to the instance location in the custom control code?










share|improve this question














This question already has an answer here:




  • Getting The Location Of A Control Relative To The Entire Screen?

    1 answer



  • How to get exact position of a panel or picturebox?

    1 answer




I have designed a custom control with a picturebox, to which a click event is associated that opens a dialogbox form:



    Private Sub pbCalendarClockSettings_Click(sender As Object, e As EventArgs) Handles pbCalendarClockSettings.Click
Dim myform As New frmCalendarClockSettings
myform.StartPosition = FormStartPosition.Manual
myform.Location = New Point(Me.Location.X, Me.Location.Y)
...


I'd like the form to open at location point of the instance of the custom control and that's what this line is supposed to do.



myform.Location = New Point(Me.Location.X, Me.Location.Y)


Unfortunately, when I instance the custom control in an application, Me.location does not seem to be the location of the instance (is offset to the top of the screen).
The custom control can be instantiated at design time and/or run time.



How do I point to the instance location in the custom control code?





This question already has an answer here:




  • Getting The Location Of A Control Relative To The Entire Screen?

    1 answer



  • How to get exact position of a panel or picturebox?

    1 answer








vb.net winforms custom-controls






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 at 16:19









Alessandro Mandelli

367311




367311




marked as duplicate by Visual Vincent, Jimi, IvanH, WelcomeOverflow vb.net
Users with the  vb.net badge can single-handedly close vb.net questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 23 at 0:44


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Visual Vincent, Jimi, IvanH, WelcomeOverflow vb.net
Users with the  vb.net badge can single-handedly close vb.net questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 23 at 0:44


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • ...or actually, even better: Getting The Location Of A Control Relative To The Entire Screen?
    – Visual Vincent
    Nov 22 at 17:24










  • It's not a duplicate. Point location = someControl.PointToScreen(Point.Empty) requires you to know the name of the instance of the custom control. My case is different: the instance of the custom control needs to know its own position.
    – Alessandro Mandelli
    Nov 22 at 18:07








  • 2




    All controls are aware of their own positions. If you need to get the screen coordinates from within the control itself just replace the name with Me, like so: Dim Location As Point = Me.PointToScreen(Point.Empty) - it works the same way as when you use Me inside a form.
    – Visual Vincent
    Nov 22 at 19:06












  • PointToScreen() is a member of all controls so you don't necessarily need to know the name of which one to target, all you need is an instance (Me refers to the current instance).
    – Visual Vincent
    Nov 22 at 19:11








  • 1




    No, you don't need to know the name of the instance. You need to have a reference to the instance. A variable that refers to an object is not the name of the object. As suggested, every object can refer to itself using Me. You're even already doing that in the code you posted so you already know that. This is a case of having two bits of information but not putting them together.
    – jmcilhinney
    Nov 22 at 22:48


















  • ...or actually, even better: Getting The Location Of A Control Relative To The Entire Screen?
    – Visual Vincent
    Nov 22 at 17:24










  • It's not a duplicate. Point location = someControl.PointToScreen(Point.Empty) requires you to know the name of the instance of the custom control. My case is different: the instance of the custom control needs to know its own position.
    – Alessandro Mandelli
    Nov 22 at 18:07








  • 2




    All controls are aware of their own positions. If you need to get the screen coordinates from within the control itself just replace the name with Me, like so: Dim Location As Point = Me.PointToScreen(Point.Empty) - it works the same way as when you use Me inside a form.
    – Visual Vincent
    Nov 22 at 19:06












  • PointToScreen() is a member of all controls so you don't necessarily need to know the name of which one to target, all you need is an instance (Me refers to the current instance).
    – Visual Vincent
    Nov 22 at 19:11








  • 1




    No, you don't need to know the name of the instance. You need to have a reference to the instance. A variable that refers to an object is not the name of the object. As suggested, every object can refer to itself using Me. You're even already doing that in the code you posted so you already know that. This is a case of having two bits of information but not putting them together.
    – jmcilhinney
    Nov 22 at 22:48
















...or actually, even better: Getting The Location Of A Control Relative To The Entire Screen?
– Visual Vincent
Nov 22 at 17:24




...or actually, even better: Getting The Location Of A Control Relative To The Entire Screen?
– Visual Vincent
Nov 22 at 17:24












It's not a duplicate. Point location = someControl.PointToScreen(Point.Empty) requires you to know the name of the instance of the custom control. My case is different: the instance of the custom control needs to know its own position.
– Alessandro Mandelli
Nov 22 at 18:07






It's not a duplicate. Point location = someControl.PointToScreen(Point.Empty) requires you to know the name of the instance of the custom control. My case is different: the instance of the custom control needs to know its own position.
– Alessandro Mandelli
Nov 22 at 18:07






2




2




All controls are aware of their own positions. If you need to get the screen coordinates from within the control itself just replace the name with Me, like so: Dim Location As Point = Me.PointToScreen(Point.Empty) - it works the same way as when you use Me inside a form.
– Visual Vincent
Nov 22 at 19:06






All controls are aware of their own positions. If you need to get the screen coordinates from within the control itself just replace the name with Me, like so: Dim Location As Point = Me.PointToScreen(Point.Empty) - it works the same way as when you use Me inside a form.
– Visual Vincent
Nov 22 at 19:06














PointToScreen() is a member of all controls so you don't necessarily need to know the name of which one to target, all you need is an instance (Me refers to the current instance).
– Visual Vincent
Nov 22 at 19:11






PointToScreen() is a member of all controls so you don't necessarily need to know the name of which one to target, all you need is an instance (Me refers to the current instance).
– Visual Vincent
Nov 22 at 19:11






1




1




No, you don't need to know the name of the instance. You need to have a reference to the instance. A variable that refers to an object is not the name of the object. As suggested, every object can refer to itself using Me. You're even already doing that in the code you posted so you already know that. This is a case of having two bits of information but not putting them together.
– jmcilhinney
Nov 22 at 22:48




No, you don't need to know the name of the instance. You need to have a reference to the instance. A variable that refers to an object is not the name of the object. As suggested, every object can refer to itself using Me. You're even already doing that in the code you posted so you already know that. This is a case of having two bits of information but not putting them together.
– jmcilhinney
Nov 22 at 22:48

















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

What visual should I use to simply compare current year value vs last year in Power BI desktop

Alexandru Averescu

Trompette piccolo