Just what I needed. Just complicated enough to get me started but short enough to get going quickly. Thanks much!!
@martinomasreiter31249 жыл бұрын
Cool drawings, well done. Some suggestions: 1) Use the e.graphics EventArgs of your paint event for drawing, instead of creating a new instance. 2) Use control.invalidate method to force to repaint the full control. (slight difference to your refresh method) PS: We did a similar thing in phyton, fun stuff ;)
@TheCerubus8 жыл бұрын
Great video program works as promised (once I found the line of code I left out) and gave me a basic understanding of C# graphics. The only negative is that I believe that it is still recommended to dispose of the pen and other drawing tools when you are done.
@ToyLikeChannel5 жыл бұрын
Wow, it works under SharpDevelop! Thank you, your video was really helpful, your explanation was clear and detailed.
@Cruz0e2 жыл бұрын
your conversion is equal to * π/180 (because 180 degree in radians is π), so if you want to, you could use *Math.Pi/180 instead easy to memorize 180=π (once you understand what it is) π is a perimeter of a semicircle (180 degree) with radius of 1 if 180° is π then 1° is equal to π/180 your angle is ω[deg] then your ω[rad] = ω[deg]*π/180 (I used 2π/360 first, bit mixed it up so I edited to correct it, but it's the same thing 2π is the perimeter of a circle)
@lemonandgaming60135 жыл бұрын
oh boi the abstract art this program makes is impressive
@anadibrothers-yourwaytorel52593 жыл бұрын
Exactly
@NetMistro3 жыл бұрын
Thanks for this. You explain very well.
@brianbrewster65326 жыл бұрын
Thanks, Chris. Really got my creative juices flowing watching this fascinating video. I think if I can translate this to VB I might be able to experiment with this powerful app to make intricate patterns for a project I'm working on. Also, at 35:00, I saw a semblance of a wormhole. This would be a dream come true if I could figure out how to draw something like this and turn it into an animation! Thank you so much, sir.
@omerodabasi7 жыл бұрын
Very helpful tutorial, subbed!
@bboyrd019 жыл бұрын
Thank you So much chris merritt, This will be highly useful for my research.
@james9700272 жыл бұрын
great demonstration it helped a lot - just wish visual studio was actually a good software, i spent way over an hour to basically follow what you have done just down to how purely buggy visual studio is on my laptop sadly lol
@Ivan679684 жыл бұрын
Vert nice and interesting! Learned a lot! Thank you👍😀
@NimishP2 жыл бұрын
@27:10 To convert degrees to radian multiply degrees with PI / 180 instead. This will reduce error to a great extents. Math library has predefined constant PI.
@tuananhvu64483 жыл бұрын
It's help me a lot, thanks 4 tutorial
@hz66124 жыл бұрын
Amaaaaaazing!!
@trunghoale85849 ай бұрын
System.NullReferenceException: 'Object reference not set to an instance of an object.' g was null. Help me?????
@tomwilson45728 жыл бұрын
A neat idea for demonstrating Graphics in a WinForm though the implementation could be a little tidier.
@langtonmwanza66898 жыл бұрын
i know right like having the draw function just take the graphics surface as an argument
@shohanvlogs19872 жыл бұрын
Good video
@Greebstreebling2 жыл бұрын
thank you for sharing this, there's loads of good stuff, presented in an engaging and effective way. In my application I set a bacground image in the panel. When I do that the lines do not draw over the background image. Any ideas ?
@Greebstreebling2 жыл бұрын
I found an answer and what worked for me was to add the following: static Bitmap baseImage = (Bitmap)Image.FromFile(@"C:\Compass_Images\Capture.png"); and in the Canvas_Paint method, add in the following line, just before drawline(): Canvas.BackgroundImage = baseImage; When this runs, the line is drawn on top of the background image.
@harishmehta29923 жыл бұрын
Thanks, very good video
@gunteramberg19492 жыл бұрын
so many thanks, this is great one question to you, if you want to go a step back, what is the code ??
@Obishman5 жыл бұрын
Thanks, excellent video
@MessingWithCode2 жыл бұрын
i love it
@nasredeenyousif59114 жыл бұрын
Good tutorial ...I see that you do not use the increment parameter what are the dimensions (initial) of your form (Form1)?
@chrisconn56498 жыл бұрын
I appreciate the video, the graphics basics were helpful, but I was getting a little frustrated that you weren't quite sure where you were going sometimes. Regardless, thanks. Also, I think Pi/180 coverts radians to angles
@zacheryhenry65808 жыл бұрын
I think I must have something wrong with the button click function but I can't find it. If I manually input the number of lines and everything and start the program it works correctly but then when I hit go the canvas just wipes. So I think it does the line drawing portion correctly and when I click the button it wipes the canvas but doesn't appear to re-do everything when I hit go idk
@lewisoliver51487 жыл бұрын
Thanks. Helped me a lot ^^
@titusdrake90374 жыл бұрын
Great tutorial. Only one question: where, in the code, we use my_increment variable? Or it is not used? Thankyou!
@انامسلموكفى3 жыл бұрын
I need Help please i how i could draw a schape in runtime
@70ME3E9 жыл бұрын
love it, thank you! :)
@zacheryhenry65808 жыл бұрын
We're you able to see the code I pasted here or do I need to paste it in the other location you mentioned? I feel like it has to be something simple it's driving me nuts
@konstantinkirilov9671 Жыл бұрын
Does someone else has the warnings with the code on the static int my_incrememt,num_lines, center_x,center_y and another warning on Graphics g = null; please help if someone has a solution
@x_salaheddinechannel_x4 жыл бұрын
Hello, I want to help me, Can i put the point = (12.5 , 14.6), Thank you.
@KeenanWoodall10 жыл бұрын
Could you post the source. I'm very new, typed something wrong, and visual is freaking out at me. I can't open the script so I can't fix it. Also where it says "private void canvas_Paint(object sender, PaintEventArgs e)" it said for me "private void panel1_Paint(object sender, PaintEventArgs e)" I changed its name to panel in the properties window a few minutes prior, so I wan't sure why is said panel1 instead of canvas. I think it messed everything up when I changed the methods name to canvas_Paint
@gopalakrishnanudhayasuriya198310 жыл бұрын
Hey,is it possible fit drawing inside the panel,when i am giving high values to line it goes outside of panel...help me
@xorxpert6 жыл бұрын
Gopalakrishnan Udhayasuriyan then you clamp/bound the values before it’s drawn 🤦♂️ For ex, if X > width then X = width - X vice versa. Do the same for Y
@mr.tuttifrutti92807 жыл бұрын
It was cool, dude!
@tomg20024 жыл бұрын
Great video, thanks! Does Graphics.DrawLine create something that can be counted, later? Like... could you say, for each... line that is green... count'em up? Is it an vector that persists beyond changing the pixel colors? I'm still kicking around my first "good idea" and your demonstration helped a lot.
@NimishP2 жыл бұрын
AutoCAD or MicroStation would be better choice if you want to manipulate these entities for future.
@chriswinchester48059 жыл бұрын
Very good video, not hard to follow at all. I did, however, have a problem with creating a null Graphics object. I am using VS 2013. What should I put in the parameters?
@chriswinchester48059 жыл бұрын
I found that I left out some important code under the drawLine function. All is good now.
@trunghoale85849 ай бұрын
@@chriswinchester4805 can you see that problem? my problem: System.NullReferenceException: 'Object reference not set to an instance of an object.' g was null
@Bostonite198510 жыл бұрын
Every time I try to run the program, I get a 'build errors' message. What has gone wrong?
@BdyPhrk8 жыл бұрын
Does this use the CPU or GPU to draw ?
@JayPaysLPs8 жыл бұрын
+B100dyPhr34k CPU
@damonmangrum580510 жыл бұрын
im having trouble with the new new Point(start_x,start_y); new Point(start_x+100,start_y+100); it keeps asking me to add { } to it
@Ropad109 жыл бұрын
Hi, I'd like to make a game, I'm trying to learn Java, but I find C# alot easier to learn as my first language. Is it possible to create sprites through paint or other drawing programs and use them in c#?
@alecr4749 жыл бұрын
Kevin Hansen yes, usually it is easier to use a different library/engine then basic .NET (the C# and visual basic libraries and format), using XNA, mono, or unity plugins for visual studio, otherwise you would use a WPF form instead of a windows form. WPF is made for 2D and 3D graphic handling. I am sure you can use win-forms, but i am just listing the easiest methods.
@bj0urne6 жыл бұрын
When i'm at the point of drawing at the end, after all the code is good, the lines does all wierd kinds of shit, they are not that square that you got, and i double checked our code.
@chriswinchester48059 жыл бұрын
I wonder if an engineer (financial or mechanical) could create a calculator, so that the calculator outputs would then become the inputs for lineDraw.
@alecr4749 жыл бұрын
Chris Winchester that is very possible. what i would do is create three double variables, one to hold the operator used by the calculator user, and the other two to be the numbers they put in. then, after the computer does operations, i would pass those variables to a draw method to get lines.
@butterdogestarwars67094 жыл бұрын
Is there a way to save the image?
@ahmadsaleh46288 жыл бұрын
Hello Please help I want CaseTools in C# to do something like the shadow in photoshop anything else please help me
@PaulKruskamp8 жыл бұрын
cool, subbed
@doro5165 жыл бұрын
do you what can I use instead of canvas, in my visual studio version it doesn't include canvas
@ferna22945 жыл бұрын
"canvas" was the name of the panel he used to draw. You have to name your panel "canvas" in order to use it. 8:58 On the right of the screen you can read "(name) canvas"
@boliussa8 жыл бұрын
By 20:32 You've declared Graphics g,.. and done g.drawLines.... How does it know what panel or form to draw it on?
@tomwilson45728 жыл бұрын
+boliussa Use the Graphics object passed to the Paint event handler private void canvas_Paint(object sender, PaintEventArgs e) { for (int i = 0; i < _lines; ++i) // _lines=Int32.Parse(number_of_lines.Text) { DrawLine(e.Graphics); } } Modify DrawLine to use this graphics object instead of canvas.CreateGraphics() private void DrawLine(Graphics g) { ... g.DrawLines(_pen, points); ... }
@boliussa8 жыл бұрын
Thanks. Where you write " use this graphics object instead of canvas.CreateGraphics()" That suggests that's advantageous.. So, what is the difference between doing canvas.createGraphics() and canvas.DrawLines() vs doing e.Graphics.Drawlines/g.DrawLines?
@tomwilson45728 жыл бұрын
+boliussa There is no functional difference, however, +Chris Merritt is creating a second Graphics object, when there is already one available via PaintEventArgs. It is also GDI+ good practice and saves resources.
@hasnatqureshi11888 жыл бұрын
Can any one tell me how can I simulate data structures in c# like stacks,queues and link lists
@chrismerritt72918 жыл бұрын
+Hasnat Adil That would be a tutorial all of its own. You can build your own classes to make linked lists, queues, and stacks. Perhaps I'll build a tutorial in the near future around those.
@ddragomirov8 жыл бұрын
Hi, I want to ask you if there is a way that I can alter the speed of the pen so that it looks like an animation ?
@chrismerritt72918 жыл бұрын
+Dayan Dragomirov Hmmm. You could put the main thread to sleep after every line is drawn. google C# Thread.Sleep
@ddragomirov8 жыл бұрын
Thank you for the answer, but I want to slow down the drawing of the line itself so I don't think sleeping would work in that case.
@MrKaprson8 жыл бұрын
Drawing of the line itself is a single procces that you cannot influence. You would have to create a cycle where length of the line (in pixels) is the amount of steps and one single dot must be drawn in each step. Then you can thread.Sleep(theAmounOfATime).
@MrKaprson8 жыл бұрын
Hope you get me >]
@VStyleMentVS8 жыл бұрын
Is this code means end_x=(int) (start_x + Math.Cos(my_angle * ...)* my_length) thise end_x= start_x + Math.Cos(my_angle * ...)* my_length ??
@tomwilson45728 жыл бұрын
+Василь Кохан my_angle needs to be in radians (without the hideous long decimal fraction) and is best declared as double rather than int for the trigonometry calculation. The result then needs converting to an int for end_x. // convert degrees to radians double cosAngle = Math.Cos(_angle * Math.PI / 180.0); double sinAngle = Math.Sin(_angle * Math.PI / 180.0); _endx = (int)(_startx + _length * cosAngle); _endy = (int)(_starty + _length * sinAngle); BTW I prefer a naming convention that distinguishes local variables from class member variables (these have an underscore prefix).
@langtonmwanza66898 жыл бұрын
also instead of Point you can used PointF.....it acepts decimal coordinates and handles them much better than just simple rounding off
@igorflamenguista18 жыл бұрын
Guys, i've got a problem... when I write about the class canvas, this problem show up: The name 'canvas' does not exist in current context. I've searched out and I was supposed to put using System.Windows.Controls but visual studio didnt recognize that namespace. btw im using vs2012 windows 8.
@TheJazz7478 жыл бұрын
+igorflamenguista1 he renamed the panel in which he was drawing the stuff "canvas". to you it should be like "panelX" where X is your panel number.
@zacheryhenry65808 жыл бұрын
I'm stuck I've been trying to get this to work for so long. When I start my program 1 horizontal line is there like in the video but when I hit go the line just disappears.
@chrismerritt72918 жыл бұрын
Can you paste your code in pastebin and share the link?
@zacheryhenry65808 жыл бұрын
I'm not familiar with pastebin. I posted my code in the comment above though
@zacheryhenry65808 жыл бұрын
Thanks for any help if you can though. I love this idea and have been trying for so long to get it to work I just can't figure out where i made an error. I feel it has to be with the button clicking
Use the following code snippet to convert from degrees to radians // convert degrees to radians double angleRadians = angleDegrees * Math.PI / 180.0;
@FelixPow18 жыл бұрын
+Tom Wilson Thank you very much sir! Your way to convert from degrees to radians makes the drawing perfect
@dylanhynds58777 жыл бұрын
Does anyone have the end source code? I'm having trouble with the variables "Colour" and "Black" (Just so everybody knows iv'e only just started this and i haven't made it to the end)
@dylanhynds58777 жыл бұрын
its ok i fixed my error
@zacheryhenry65808 жыл бұрын
So I got it to work but it's probably not the correct way. I pasted this inside of the button_click portion after canvas refresh: myPen.Width = 1; my_length = Int32.Parse(length.Text); g = canvas.CreateGraphics(); for (int i = 0; i < Int32.Parse(number_of_lines.Text); i++) drawline(); It's basically the canvas portion that wasn't getting called when i clicked go, only the canvas refresh part was. Copying this down in the button_click section after canvas refresh caused it to work idk what the downsides of this would be
@JohnnyPhoenix10 жыл бұрын
How can I donate (trollish nickname apart)?
@chrismerritt729110 жыл бұрын
Haha. I like your handle. There's a donate button on my channel home page @ the top right. kzbin.info/door/hKYo_FJBF1aMV7VVWXkO9A. Thanks!
@damonmangrum580510 жыл бұрын
nevermind i got it there was no semi colon thanks
@JensHallgren7 жыл бұрын
OMG, this is really scary... no offence, but... you are supposed to have some skills in coding (I suppose?), and still messing things up in this tiny example so you don't really know what is happening (I've been watching until 31.20 by now) .... Isn't there any method to actually ..eh.. get it right without lots of trial and error and guessing? Imagine you are working on a huge project with many files and many thousand lines of code? What if you code everything in this manner, it would be soaked with bugs.... some that you might discover, some you will never discover until it's too late..... Thanks anyway for a good introduction to Visual Studio and to draw graphics. Just what I needed. (I'm into embedded systems, so I haven't done much "Windows" stuff yet.). It's really good teaching to explain everything , like how to set up the controls with labels, textboxes and a button.
@Greebstreebling2 жыл бұрын
when you say it's really scary, was your life at risk? Perhaps a sense of perspective would be good - and cut the author some slack for helping the rest of us out big time. From an educational perspective, talking as you 'do' is a great way to help folks learn.
@mathewo92097 жыл бұрын
Dear god, why are you called CreateGraphics inside the paint ever. That's a bad idea, never do that, use the graphics class provided by the method, that's the whole paint of the paint event.
@damonmangrum580510 жыл бұрын
new Point(start_x,start_y); new Point(end_x,end_y);
@krimbelkacem575110 жыл бұрын
how to print on the paper your work using c#
@ismaelgoldsteck59748 жыл бұрын
dispose your graphics object!
@damonmangrum580510 жыл бұрын
{ } expected
@ctbram062710 жыл бұрын
You should maybe practice or write your example and test it before recording. By 37 minutes and 35 seconds I was totally confused because of the logic mistakes. Also a good 5 minutes of you kind of scratching your head does not make for exciting viewing.