CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Nov 2010
    Posts
    6

    Unsure of the proper way to use Form.Location...

    I am trying to pull coordinates for a form location out of a database and insert them into the Location property:

    Code:
    childForm.Location = new Point(/* coordinates go here */);
    I have tried doing a direct replacement with the DataSet (which didn't work):

    Code:
    childForm.Location = new Point((string)row["location"]);
    And I have tried using a string to hold the coordinates:

    Code:
    string Loc = (string)row["location"];
    childForm.Location = new Point(Loc);
    ...which also didn't work. If I print 'Loc' to the screen, I can see it passing valid coordinates (in this case "100, 200" and "300, 600"), but it errors out when I try to pass that information to childForm.Location.

    Obviously I'm doing something very wrong here, but I was unable to find any examples of using non-static or non-relative coordinates. If you know, could you please tell me what my misatke is?

    Thanks!
    -Charlie

  2. #2
    Join Date
    Aug 2008
    Posts
    902

    Re: Unsure of the proper way to use Form.Location...

    Quote Originally Posted by CharlieHolt View Post
    ...
    What you are doing makes no sense. Look at Point's constructor overloads using intellisense.

    Do you see one that looks like this: Point.Point(string str) ?

    If you don't see a constructor overload with a string type parameter, then why would it make sense to try to initialize a point with a string?

    Knowing what a Point is and what it's used for, would this make any sense at all?

    Code:
    Point myPoint = new Point("Hello, World!");

  3. #3
    Join Date
    Nov 2010
    Posts
    6

    Re: Unsure of the proper way to use Form.Location...

    Chris, valid point but it didn't help me a single bit.

    I don't care if you're condescending, but the least you could do after mocking me is show me a correction.

  4. #4
    Join Date
    Aug 2008
    Posts
    902

    Re: Unsure of the proper way to use Form.Location...

    Quote Originally Posted by CharlieHolt View Post
    Chris, valid point but it didn't help me a single bit.

    I don't care if you're condescending, but the least you could do after mocking me is show me a correction.
    My apologizes if I came off condescending. Some people might not even understand the problem.

    That being said, I can't help you with the solution as I'm unfamiliar with DataSet. I don't work with SQL at all.

    What type is row["location"]? Is it a string? If so, exactly how are they formatted?
    Last edited by Chris_F; November 22nd, 2010 at 11:17 PM.

  5. #5
    Join Date
    Nov 2010
    Posts
    6

    Re: Unsure of the proper way to use Form.Location...

    It can be an int or a string. I have it as a string at the moment. (it carries coordinate values, raw numbers with a comma dividing them - that is it. ie: 20, 100).

  6. #6
    Join Date
    Aug 2008
    Posts
    902

    Re: Unsure of the proper way to use Form.Location...

    Quote Originally Posted by CharlieHolt View Post
    It can be an int or a string. I have it as a string at the moment. (it carries coordinate values, raw numbers with a comma dividing them - that is it. ie: 20, 100).
    In that case it shouldn't be difficult.

    Code:
    childForm.Location = StringToPoint((string)row["location"]);
    
    private Point StringToPoint(string str)
    {
        string[] s = str.Split(',');
        int x = Int32.Parse(s[0]);
        int y = Int32.Parse(s[1]);
        return new Point(x, y);
    }

  7. #7
    Join Date
    Nov 2010
    Posts
    6

    Re: Unsure of the proper way to use Form.Location...

    And now I can see why I was being foolish...

    Thank you very much, Chris!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured