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!
Printable View
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!
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.
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:
Is there a similar method in VB.Net?Code:Me.scale (-100,100)-(100,-100)
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.
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:
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.Code:Me.Scale (-Me.ScaleWidth / 2, Me.ScaleHeight / 4)-(Me.ScaleWidth / 2, -3 * Me.ScaleHeight / 4)
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?
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.
Here it is, as promised. Sorry for the wait. I got distracted by something shiny. ;)
Here's another one you might find interesting.
Thank you very much for all that! Now I can see how TranslateTransform method works!:thumb:
Sorry for getting back. I applied TranslateTransform method for Me.MainGraphics ( Graphics object which I created on the form) in the following code:
in both Form_Load and Form_Resize events.Code:MainGraphics.TranslateTransform(Me.ClientSize.Width / 2, Me.ClientSize.Height / 2)
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?
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.
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.
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.
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?
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
(Accidental double posting. Why can't I delete a blank message?)
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.
Thank you again! It worked.:D