• Keine Ergebnisse gefunden

Grundlagen in Visual Studio MFC und .net

N/A
N/A
Protected

Academic year: 2021

Aktie "Grundlagen in Visual Studio MFC und .net"

Copied!
33
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Grundlagen in Visual Studio MFC und .net

Dipl.-Inf., Dipl.-Ing. (FH) Michael Wilhelm Hochschule Harz

FB Automatisierung und Informatik mwilhelm@hs-harz.de

Raum 2.202

Tel. 03943 / 659 338

(2)

Inhalt

1. Einführung in .net

2. Dialogfenster / SDI

3. Grafik

(3)

DrawArc DrawBezier DrawBeziers

DrawCloseCurve DrawEllipse

DrawLine DrawPath DrawPie

DrawPolygon DrawRectangle DrawString

Wichtige Grafik-Methoden

FillCloseCurve FillEllipse

FillPath FillPie

FillPolygon

FillRectangle

FillRegion

DrawImage

(4)

Konstruktoren:

DrawLine

public void DrawLine(

Pen pen, Point pt1, Point pt2 )

public void DrawLine(

Pen pen,

int x1,int y1,

int x2,int y2

(5)

Erstellen eines neuen Projektes

o

Name: Grafik1

Rechte Maustaste, Properties Eintrag „paint“

Doppelklick

1. Beispiel:

(6)

Paint-Methode in der Form von Grafik1

Form_load() {

this.ResizeRedraw = true;

this.DoubleBuffered = true;

}

// e ist die Referenz auf die Leinwand

private void Form1_Paint(object sender, PaintEventArgs e) {

Graphics g = e.Graphics;

Pen pen = new Pen(Color.Black, 3);

g.DrawLine(pen,10,10, 400,200);

pen.Dispose();

(7)
(8)

using System.Drawing.Drawing2D

DashStyle.DashDot;

DashStyle.Dash;

DashStyle.DashDotDot;

DashStyle.Dot;

DashStyle.Solid;

DashStyle.DashDot;

DashStyle.Custom;

Linestyles

myPen.DashStyle = DashStyle.DashDot;

(9)

public void DrawRectangle(

Pen pen,

Rectangle rect )

public void DrawRectangle(

Pen pen,

int x, int y,

int width, int height Konstruktoren:

DrawRectangle

(10)

Beispiel

(11)

Beispiel

Graphics g = e.Graphics;

Pen pen = new Pen(Color.Black, 3);

Pen pen2 = new Pen(Color.Red, 6);

Rectangle rect = new Rectangle(10, 10, 200, 200);

g.DrawRectangle(pen, rect);

g.DrawRectangle(pen2, 20, 20, 180, 180); // width, height

pen.Dispose();

pen2.Dispose();

(12)

public void DrawEllipse(

Pen pen,

Rectangle rect )

public void DrawEllipse(

Pen pen,

int x, int y,

int width, int height Kontruktoren:

DrawEllipse

(13)

Beispiel

(14)

Konstruktoren:

DrawString

public void DrawString(

string s, Font font, Brush brush, PointF point )

public void DrawString(

string s,

Font font,

Brush brush,

PointF point,

(15)

Methoden:

Font

public void Font(

string Fontname, float emSize);

public void Font(

string Fontname,

float emSize,

FontStyle style

);

(16)

Methoden:

SolidBrush: Version1

SolidBrush drawBrush = new SolidBrush(Color.Black);

(17)

Methoden:

HatchBrush: Version2

Brush mybrush = new HatchBrush(

HatchStyle.DiagonalCross, Color.Green

);

(18)

BackwardDiagonal

Cross

DarkDownwardDiagonal

DarkHorizontal

DashedVertical

DiagonalBrick

DiagonalCross

DottedDiamond

DottedGrid

ForwardDiagonal

Horizontal

LargeGrid

Min

NarrowHorizontal

NarrowVertical

Percent05

Percent10

Percent90

SmallGrid

SolidDiamond

Sphere

Trellis

Vertical

Wave

(19)

Brush mybrush1 =

new HatchBrush(HatchStyle.DiagonalCross, Color.Green);

Brush mybrush1 =

new HatchBrush(HatchStyle.DiagonalCross, Color.Green, Color.White);

g.FillEllipse(mybrush1, 152, 112, 150, 80);

Brush mybrush2 =

new HatchBrush(HatchStyle.ZigZag, Color.Red);

g.FillEllipse(mybrush2, 10, 11, 120, 80);

Beispiel HatchBrush mit FillEllipse

(20)
(21)

Methoden:

LinearGradientBrush: Version3

Brush mybrush =

new LinearGradientBrush(

point,

point,

Color,

Color

);

(22)

Point p1 = new Point(0, 0);

Point p2 = new Point(200, 100); // Größe des Schemas mybrush = new LinearGradientBrush(

p1, // absolute Koordinaten p2, // absolute Koordinaten Color.Red,

Color.Blue );

g.FillEllipse(mybrush, 50, 50, 300, 200);

Beispiel mit LinearGradientBrush

(23)
(24)
(25)

Beispiele mit DrawString

Font drawFont1 = new Font("Arial", 16);

Font drawFont2 = new Font("Courier New", 16, FontStyle.Bold | FontStyle.Underline );

SolidBrush drawBrush = new SolidBrush(Color.Black);

PointF drawPoint = new PointF(50.0F, 55.0F);

g.DrawString("Hier ist ein Text", drawFont1, drawBrush, drawPoint);

g.DrawString("Hier ist zweiter Text", drawFont2, drawBrush,

(26)
(27)

Graphics g = this.CreateGraphics();

SizeF sf = g.MeasureString("FFFFFF:F", drawFont1);

sf = g.MeasureString("MMMM", drawFont1);

leftMargin = (int)sf.Width;

rightMargin = (int) sf.Width;

int zeilenhoehe = (int) sf.Height;

Beispiele mit DrawString, Abmessungen

(28)

Erstellen eines neuen Projektes

o

Name: Grafik2

Eintragen eines Panels

Rechte Maustaste, Properties Eintrag „paint“

Doppelklick

2. Beispiel:

(29)

Beispiele mit DrawImage und DrawPolygon

Pen blackPen = new Pen(Color.Black, 3);

Point point1 = new Point(50, 50); Point point2 = new Point(100, 25);

Point point3 = new Point(200, 5); Point point4 = new Point(250, 50);

Point point5 = new Point(300, 100); Point point6 = new Point(350, 200);

Point point7 = new Point(250, 250);

Point[] curvePoints = { point1, point2, point3, point4, point5, point6, point7 };

Image newImage = Image.FromFile("c:\\daten\\fotos\\bsp1.jpg");

// Punkt oben / links des Bildes Point ulCorner = new Point(10, 10);

// Draw image to screen.

g.DrawImage(newImage, ulCorner);

g.DrawPolygon(blackPen, curvePoints);

(30)
(31)

Erstellen eines neuen Projektes

o

Name: Grafik2

Eintragen eines Panels

Rechte Maustaste, Properties Eintrag „paint“

Doppelklick

2. Beispiel:

(32)

private void panel1_Paint(object sender, PaintEventArgs e) {

Color col = Color.FromArgb(255, 0, 255);

Pen pen = new Pen( col, 3);

Point point1 = new Point(100, 100);

Point point2 = new Point(500, 100);

e.Graphics.DrawLine(pen, point1, point2);

}

(33)

Referenzen

ÄHNLICHE DOKUMENTE

function MessageBox(hWnd: HWND; lpText, lpCaption: PChar;1. uType: UINT):

Sets the value for a given index; grows the array if necessary

Ein Muster stellt also eine bewährte Lösung nach Art einer Schablone für ein häufiges Probleme bereit.. So gesehen sind bereits die länger existierenden Algorithmensammlungen

// TODO: Code für Befehlsbehandlungsroutine hier einfügen CSdi_bsp1Doc* pDoc =

Die Methode fügt zwischen je zwei Elementen eines Strings-Arrays einen angegebenen trennenden Strings ein und liefert das Ergebnis a,b,c ⇒

Cette réunion a été l’occa- sion pour les spécialistes du colza de quinze pays de faire le point et d’échanger sur les derniers développe- ments en culture de colza.. Vers la

The metrics of a multiple master font program are described by one AMFM file, which specifies the control data and global font information, plus one AFM file for each of the

For a writing system such as cuneiform, the decision as to which form varieties represent distinct characters and which ones are merely minor variations of one sign, as well as the