Results 1 to 19 of 19

Thread: Changing the coordinate system

  1. #1

    Thread Starter
    Lively Member arithmetica's Avatar
    Join Date
    Jan 2009
    Location
    Ahvaz, Iran
    Posts
    89

    Question Changing the coordinate system

    Hello folks,

    I already know how to change the coordinate system using Scale method in vb6.
    I'm trying to find some method like than in .Net 2008 but I can't.
    Does any one know how to do this?

    Thanks all!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Changing the coordinate system

    Generally speaking you would call the ScaleTransform method of a Graphics object. More I can't say without a proper description of what you're actually trying to do.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member arithmetica's Avatar
    Join Date
    Jan 2009
    Location
    Ahvaz, Iran
    Posts
    89

    Re: Changing the coordinate system

    Normally, the point on the form which has (0,0) coordinates is the upper left point on a windows form. What I'm trying to do is to set another point of the form which has (0,0) coordinates.

    I used to write the following code in VB6:

    Code:
    Me.scale (-100,100)-(100,-100)
    Is there a similar method in VB.Net?

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Changing the coordinate system

    Like I said, Graphics.ScaleTransform will do that. It does it for the Graphics object you call it on only though. It's not a universal change. As I said, if you give us a proper description of what you're trying to do then we can advise further.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Lively Member arithmetica's Avatar
    Join Date
    Jan 2009
    Location
    Ahvaz, Iran
    Posts
    89

    Re: Changing the coordinate system

    I've written a code for animating a bob which is attached to a pendulum hung in the center of a form in VB6. And I use the following code in both form load and resize events:

    Code:
     Me.Scale (-Me.ScaleWidth / 2, Me.ScaleHeight / 4)-(Me.ScaleWidth / 2, -3 * Me.ScaleHeight / 4)
    Then I know the upper left point on a form is not my (0,0) point any more. So that I create my own coordinate system on a form.

    But, I'm not able to apply Graphics.ScaleTransform method in the same way as Scale method in VB6. Can you please help me further?

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Changing the coordinate system

    The ScaleTransform method is only for linear scaling of the coordinate system. There's also the TranslateTransform for linear shifting and RotateTransform for rotation about the current origin.

    For instance, if you call ScaleTransform and pass 2.0F and 2.0F as arguments then anything you draw using that Graphics object will be twice as large in both directions and twice as far from the origin.

    As I said, you call these methods on a Graphics object and then the change applies only on drawing performed using that Graphics object. Where that Graphics object comes from is up to you but one of the most common scenarios would be using the e.Graphics property in a Paint event handler. I will create a little sample that shows usage for the three methods mentioned above.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Lively Member arithmetica's Avatar
    Join Date
    Jan 2009
    Location
    Ahvaz, Iran
    Posts
    89

    Re: Changing the coordinate system

    Quote Originally Posted by jmcilhinney View Post
    I will create a little sample that shows usage for the three methods mentioned above.
    Thank you very much for doing that.

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Changing the coordinate system

    Here it is, as promised. Sorry for the wait. I got distracted by something shiny.
    Attached Files Attached Files
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Changing the coordinate system

    Here's another one you might find interesting.
    Attached Files Attached Files
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  10. #10

    Thread Starter
    Lively Member arithmetica's Avatar
    Join Date
    Jan 2009
    Location
    Ahvaz, Iran
    Posts
    89

    Resolved Re: Changing the coordinate system

    Thank you very much for all that! Now I can see how TranslateTransform method works!

  11. #11

    Thread Starter
    Lively Member arithmetica's Avatar
    Join Date
    Jan 2009
    Location
    Ahvaz, Iran
    Posts
    89

    Question Re: Changing the coordinate system

    Sorry for getting back. I applied TranslateTransform method for Me.MainGraphics ( Graphics object which I created on the form) in the following code:

    Code:
     MainGraphics.TranslateTransform(Me.ClientSize.Width / 2, Me.ClientSize.Height / 2)
    in both Form_Load and Form_Resize events.

    But it just doesn't work. In fact, the ellipse I'm trying to draw in the center of the form, appears in the left upper part of the form.

    I don't know where I did wrong. Can you please help again?

  12. #12
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Changing the coordinate system

    First of all, you shouldn't be creating any Graphics objects in those event handlers. The ONLY place you should be doing any drawing is in the Paint event handler, and then ONLY using e.Graphics. Fix that and then let me know if there's still an issue.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  13. #13

    Thread Starter
    Lively Member arithmetica's Avatar
    Join Date
    Jan 2009
    Location
    Ahvaz, Iran
    Posts
    89

    Re: Changing the coordinate system

    I was able to draw my graphics using e.Graphics in Paint event handler. But my problem is that I need to update the graphics every millisecond using a timer. How can I do this? In VB6 I simply would place the code in the timer event handler. However, VB.Net 2008 graphics sounds a little more difficult.

  14. #14
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Changing the coordinate system

    As I said, you do all your drawing in the Paint event handler. If you need to force a repaint you need to raise the Paint event, which you do by calling Refresh or Invalidate and Update.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  15. #15

    Thread Starter
    Lively Member arithmetica's Avatar
    Join Date
    Jan 2009
    Location
    Ahvaz, Iran
    Posts
    89

    Question Re: Changing the coordinate system

    Sorry for getting back over and over. I did what you said. But I see the graphics terribly flickers in run time. I found some solutions here:

    http://www.developerfusion.com/code/...fering-in-net/

    But they didn't work for me!
    What's the best solution for lowering flickers when using e.Graphics?

  16. #16
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Changing the coordinate system

    A windows form or other control has to be double buffered in order to show a moving or changing image without flickering. A non-double-buffered drawing surface is a common cause of flickering (although not the only possible one). The code you pointed doesn't seem very successful, and somehow that doesn't surprise me.

    If you are drawing the pendulum on a form, it's easy: just set the Form's DoubleBuffered to True, either in the designer or in code. If that doesn't help, we'll have to look for another cause.

    An alternative would be to draw the pendulum in a picture box, because that is double buffered by default. It would have an advantage that you could position the drawing anywhere on the form without using transforms. Again, you could do it in the designer or in code.

    bye, BB

  17. #17
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Changing the coordinate system

    (Accidental double posting. Why can't I delete a blank message?)

  18. #18
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Changing the coordinate system

    As boops boops says, a PictureBox is a good way to go. If you check out the examples I posted, the first one draws on the form directly and will flicker a lot when you hold down one of the spinner buttons. The second one draws on a PictureBox and the "animation" is smooth, even though I have the Timer Interval set to a very low value.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  19. #19

    Thread Starter
    Lively Member arithmetica's Avatar
    Join Date
    Jan 2009
    Location
    Ahvaz, Iran
    Posts
    89

    Resolved Re: Changing the coordinate system

    Thank you again! It worked.

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