[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Winform Activeform Location of X and Y coordinate C# code

Posted on 2011-10-15
5
Medium Priority
?
637 Views
Last Modified: 2013-12-16
I am trying to use the current x, and y position of the active form, to determine the current x and y mouse coordinates for a given (webbrowser) in the Main form of the application. As coordinates of the form will change depending on resolution, I am looking to ensure the mouse coordinates displayed are always only current with the browser form.

int NewTopBorderValueX = Main.ActiveForm.DesktopBounds.Location.X;
int NewTopBorderValueY = Main.ActiveForm.DesktopBounds.Location.Y;

I set up the above two variables to subtract these values when the form position changes from 0,0.

However, it asking me to use the new keyword to create an instance of the object. However, I am confused because the instance of the object is the active form.

Any suggestions on how I need to create a new instance of the active form.

Tks
0
Comment
Question by:gcastong
  • 3
  • 2
5 Comments
 

Author Comment

by:gcastong
ID: 36973543
Here is the method;

 private void tCheckMouse_Tick(object sender, EventArgs e)
        {          
            int NewTopBorderValueX = Main.ActiveForm.DesktopBounds.Location.X;
            int NewTopBorderValueY = Main.ActiveForm.DesktopBounds.Location.Y;
         
            Point pMousePosition = Control.MousePosition;
                             
            pMousePosition.X = pMousePosition.X - 33;
            pMousePosition.Y = pMousePosition.Y - 238;
                       
            tbPositionX.Text = pMousePosition.X.ToString();
            tbPositionY.Text = pMousePosition.Y.ToString();
        }

- when the form is at 0, 0, the webrowser start coordinates are X 33 and Y 238. If the form changes to let's say 50, 50, then the start of the webrowser will be X33- 50 and Y 238 -50.
0
 
LVL 17

Expert Comment

by:Carlos Villegas
ID: 36973642
Hello, I think that you really want to use is:
int NewTopBorderValueX = this.DesktopLocation.X;
int NewTopBorderValueY = this.DesktopLocation.Y;

Open in new window

0
 
LVL 17

Expert Comment

by:Carlos Villegas
ID: 36973649
Or:
if (Form.ActiveForm == null)
    return;

int NewTopBorderValueX = Form.ActiveForm.DesktopLocation.X;
int NewTopBorderValueY = Form.ActiveForm.DesktopLocation.Y;

Open in new window

0
 

Author Comment

by:gcastong
ID: 36973653
The top worked perfectly!

Thanks
G
0
 
LVL 17

Accepted Solution

by:
Carlos Villegas earned 2000 total points
ID: 36973661
You're welcome
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month19 days, 15 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question