Free Drawing trick in C#


While studying C# ,one of my friends had an idea to write  a C# program that enables user to make a free drawing shapes using C# graphics

so i have open my compiler ,have a moment of silence and started to code

My idea was to get the point when the user first clicked on the form,then while he is holding down the mouse button & moving i have to get the distance between the first position the mouse was clicked & the current position (width& height argument).

Lest’s start coding,

to get the first moue click position here we got two data members to store the first position,also w have a boolean data member to know if the mouse is still down or not

bool paintThis = false;
int x;
int y;

then in the mouse down event we get these two guys x&y of the first position and set the paintThis to true

 

private void Form1_MouseDown(object sender, MouseEventArgs e)
{
paintThis = true;
x = e.X;
y = e.Y;

}

then in the mouse up event we set the paintThis to false

 

private void Form1_MouseUp(object sender, MouseEventArgs e)
{
paintThis = false;
}

 

here in the mouse move event all the work will be done,we’ll calculate the width & the height of the rectangle we want to draw and start drawing when the mouse is down(actually when paintThis=true ) at the first position the mouse was down (x & y)

 

private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (paintThis)
{
Refresh();
Graphics gf = this.CreateGraphics();
gf.DrawRectangle(new Pen(Color.Black), x,y, e.X-x, e.Y-y);
}
}

 

here the source files    http://www.mediafire.com/?mbr69mixi76vimh

hope you have enjoyed

 

 

Getting ready for C# practical exam


3 days before my C# practical exam so i must get ready for that great event 😀 , also getting started to join the club 😀

hmmmmmmmm, to study Dr.Yusef’s slides or to get some experience from some websites i think it’s big problem.

when i have some rest to think about the matter i just take a look about some programmers CV comparing them with my little CV, then i may leave these f….n slides so go geek with some PHP codes ,yeah im totally in love with it (but also there’s some one who i can care more  and more 😉 )

so i decided to study Dr.Yusef’s slides and i have to revise 28+154+181+137 slides 😀 , but because the power of someone support i can get the job done…..

I hate matlab


in my college we have lectures about Numerical , i don’t know why i hate it but i think the reason why is the way of teaching .
After a long term (it differs from long term scheduler 😛 ) we have a practical exam,thought this whole term i didn’t even setup the matlab to just check some codes 😀
one day before the exam i started to setup this f….n program to try some code,but when i have explored the whole lectures and tutorials i thought i have to uninstall Matlab and just start to MEMORIZE all codes to pass the exam 😀

after a hard day of practical exam i have solved all the problems but im not satisfied to do that, also i still HATE MARLAB