I started learning C# to make an optics application. See here:http://natureforums.netai.net/Creati...iks/index.html
I made it using Construct 2 So I know the logic behind it.
Now I want to make this using C#. Can I make it using Visual Studio? How do I draw that line?(I used an image in Construct 2)
And How do I make the image/line always pass through the center of the lens?(I set the angle of image to that position in Construct 2)
I don't know how to do this in C#? Can you help me?
If you want to draw on a control in a Windows Forms app then you do so on that control's Paint event. I would suggest adding a PictureBox you your form and then handling its Paint event. In the event handler, you can draw whatever you like, including ellipses and lines. Do a bit of research on the Paint event of the System.Windows.Forms.Control classand you'll find plenty of examples.
When you draw a line you provide the start point and end point. If you have a start point and an angle then you need to use a bit of trigonometry to calculate the end point. Trig functions are implemented in .NET via the System.Math class.
(p.s. attached code is vb2010)
Yes, by default, 0,0 is in the upper left corner, so X increases to the Right, and Y increases going downward.
But you can use matrix transformations to put 0,0 where you want, and to scale drawings up or down, and various things.
For instance, it was mentioned that you can use Sin,Cos to calculate an endpoint given a start point and a length of line you want to draw.
But, you could also use a matrix transform to put 0,0 at the end of the line and rotate the coordinate system, so you always draw line of a given length, and at an angle of 0, but it draws at the angle you want because of the rotation. This is especially useful if you are not drawing a line, but drawing something more complicated using an image, such as a clock with stylish hands.
Here is an old example I wrote for someone in the past looking for teaching their child how to read an analog clock. So, one part of the program has you click on a label and it generates a random time and displays it in the label and on the clock.
But, it also demonstrated some of the functionality of how the clock was done, by allowing another form to be used to move the hands, scale them, and rotate.
There is not too much code to it. Since most of the functionality for the hands are the same for hour or minute hand, a class was used, instantiated twice, once for the minute hand and again for the hour hand. Haven't looked at the code in awhile, so am sure it could be improved upon.
The clock scales as the form resizes.