Florian Rappl, Department of Theoretical Physics, University of Regensburg
Graphics
var bmp = new Bitmap(400, 300)
var g = Graphics.FromImage(bmp)
Pen
(width, color)Brush
(px→color)SolidColorBrush
LinearGradientBrush
DrawRectangle()
draws the border of a rectangleFillEllipse()
fills an ellipse (could be circle)Image
classBitmap
classImage.FromFile()
reads an image to an Image
Save()
methodOnPaint()
PaintEventArgs
ClipRectangle
gives us the boundariesGraphics
gives us the graphics pointerPaint
eventListBox
control) give us a third wayDrawMode
and create an event handler (for DrawItem
)Exception
classthrow
will throw an exception or re-throw the current exceptionvoid Main() { "Before".Dump(); Sub(); "After".Dump(); }
void Sub() { "Enter".Dump(); throw new Exception("Bug"); }
//Dump() is an extension that is like Console.WriteLine()
try { /* try here */ } catch { /* catch here /* }
catch (Exception ex) {}
catch (FileNotFoundException) {}
finally {}
block is usefulreturn
in one block will still call the finallytry { "Try has been entered".Dump(); return true; }
finally { "Finally has been called".Dump(); }
IDisposable
interfaceClose()
method is importantDispose()
methodIDisposable
using
constructforeach
Dispose()
directlyusing(var fs = new FileStream(/* ... */)) {
/* Do something */
} // Resource automatically closed and freed
Type
is requiredtypeof()
(at compile-time)GetType()
Type
object contains all information about the typeFlorian Rappl, MVP Visual C#