วันจันทร์ที่ 15 กรกฎาคม พ.ศ. 2556

LAB20 การเขียนโปรแกรมกราฟ4

Bitmap bmp = new Bitmap("C:\\Users\\DV 4\\Desktop\\d.jpg");
this.SetClientSizeCore(bmp.Width + 20, bmp.Height + 20);
e.Graphics.DrawImage(bmp, 10, 10);




--------------------------------------------------------------------

Bitmap bmp = new Bitmap("C:\\Users\\DV 4\\Desktop\\d.jpg");
Rectangle destrect = new Rectangle(10, 10, bmp.Width / 2, bmp.Height / 2);
Rectangle srcrect = new Rectangle(0, 0, bmp.Width, bmp.Height);
this.SetClientSizeCore(destrect.Width + 20, destrect.Height + 20);
e.Graphics.DrawImage(bmp, destrect, srcrect, GraphicsUnit.Pixel);


-----------------------------------------------------------------------

Bitmap bmp = new Bitmap("C:\\Users\\DV 4\\Desktop\\d.jpg");
Rectangle destrect = new Rectangle(10, 10, bmp.Width , bmp.Height );
Rectangle srcrect = new Rectangle(0, 0, bmp.Width/2, bmp.Height/2);
this.SetClientSizeCore(destrect.Width + 20, destrect.Height + 20);
.Graphics.DrawImage(bmp, destrect, srcrect, GraphicsUnit.Pixel);


--------------------------------------------------------------------------

Bitmap bmp = new Bitmap("C:\\Users\\DV 4\\Desktop\\d.jpg");
Rectangle topleft = new Rectangle(0, 0, bmp.Width / 2, bmp.Height / 2);
Rectangle topright =
new Rectangle(bmp.Width / 2, 0, bmp.Width / 2, bmp.Height / 2);
Rectangle buttomleft =
new Rectangle(0, bmp.Height / 2, bmp.Width / 2, bmp.Height / 2);
Rectangle buttomright =
new Rectangle(bmp.Width/2,bmp.Height/2,bmp.Width/2,bmp.Height/2);
bmp.RotateFlip(RotateFlipType.RotateNoneFlipNone);
e.Graphics.DrawImage(bmp,topleft);
bmp.RotateFlip(RotateFlipType.RotateNoneFlipX);
e.Graphics.DrawImage(bmp,topright);
bmp.RotateFlip(RotateFlipType.RotateNoneFlipNone);
e.Graphics.DrawImage(bmp,buttomleft);
bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);
e.Graphics.DrawImage(bmp,buttomright);


---------------------------------------------------------------------------

Bitmap bmp = new Bitmap("C:\\Users\\DV 4\\Desktop\\d.jpg");
this.SetClientSizeCore(bmp.Width, bmp.Height);
Rectangle destrect = new Rectangle(0, 0, bmp.Width, bmp.Height);
Brush myBrush = new SolidBrush(Color.Coral);
e.Graphics.DrawImage(bmp, destrect);
e.Graphics.DrawString("Hello Worlddddd!!", new Font("Vernada", 30, FontStyle.Bold),
myBrush, 0, 0);





LAB19 การเขียนโปรแกรมกราฟ3

{
Point[] pt = { new Point(10,22) ,
new Point(188,246),
new Point(280,192),
new Point(250,48)
};
e.Graphics.FillClosedCurve (Brushes.Blue,pt);
e.Graphics.DrawClosedCurve (Pens.Red,pt);
}

------------------------------------------------------------------

this.SetClientSizeCore(500, 600);
HatchBrush brush;
int x = 20;
int y = 20;
foreach (HatchStyle brushStyle in Enum.GetValues(typeof(HatchStyle)))
{
brush = new HatchBrush(brushStyle, Color.Navy, Color.Yellow);
e.Graphics.FillRectangle(brush, x, y, 40, 20);
y += 30;
if ((y + 30) > this.ClientSize.Height)
{
y = 20;
x += 180;
}
}

------------------------------------------------------------------------------------

Image image = Image.FromFile("C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Blue hills.jpg");
TextureBrush brush = new TextureBrush(image);
Rectangle rect = new Rectangle(10, 10, 180, 150);
e.Graphics.FillEllipse(brush, rect);

------------------------------------------------------------------------------

private void panel1_Paint(object sender, PaintEventArgs e)
{
LinearGradientBrush pnlGdt =
new LinearGradientBrush(panel1.ClientRectangle,
Color.Yellow, Color.Navy, 0f, true);
e.Graphics.FillRectangle(pnlGdt, panel1.ClientRectangle);
pnlGdt.Dispose();
}
private void panel2_Paint(object sender, PaintEventArgs e)
{
LinearGradientBrush pnlGdt =
new LinearGradientBrush(panel2.ClientRectangle,
Color.Yellow, Color.Navy, 90f, true);
e.Graphics.FillRectangle(pnlGdt, panel2.ClientRectangle);
pnlGdt.Dispose();
}


-----------------------------------------------------------------------------

private void panel1_Paint(object sender, PaintEventArgs e)
{
LinearGradientBrush pnlGdt =
new LinearGradientBrush(panel1.ClientRectangle,
Color.Yellow, Color.Navy, 0f, true);
e.Graphics.FillRectangle(pnlGdt, panel1.ClientRectangle);
pnlGdt.Dispose();
}
private void panel2_Paint(object sender, PaintEventArgs e)
{
LinearGradientBrush pnlGdt =
new LinearGradientBrush(panel2.ClientRectangle,
Color.Yellow, Color.Navy, 90f, true);
e.Graphics.FillRectangle(pnlGdt, panel2.ClientRectangle);
pnlGdt.Dispose();
}
private void panel3_Paint(object sender, PaintEventArgs e)
{
GraphicsPath path = new GraphicsPath();
path.AddEllipse(panel3.ClientRectangle);
PathGradientBrush br = new PathGradientBrush(path);
br.CenterPoint = new PointF(panel3.ClientRectangle.Width / 2,
panel3.ClientRectangle.Height / 2);
br.CenterColor = Color.Navy;
br.SurroundColors = new Color[] { Color.Yellow };
e.Graphics.FillPath(br, path);
}
}
}



-------------------------------------------------------------------------------------

private void panel3_Paint(object sender, PaintEventArgs e)
{
GraphicsPath path = new GraphicsPath();
path.AddEllipse(panel3.ClientRectangle);
PathGradientBrush br = new PathGradientBrush(path);
br.CenterPoint = new PointF(panel3.ClientRectangle.Width / 1,
panel3.ClientRectangle.Height / 4);
br.CenterColor = Color.Navy;
br.SurroundColors = new Color[] { Color.Yellow };
e.Graphics.FillPath(br, path);
}







วันเสาร์ที่ 13 กรกฎาคม พ.ศ. 2556

LAB18 การเขียนโปรแกรมกราฟ2

private void Form1_Paint(object sender, PaintEventArgs e)
{
Pen blackPen = new Pen(Color.Black, 3);
Point point1 = new Point(100, 100);
Point point2 = new Point(200, 100);
e.Graphics.DrawLine(blackPen, point1, point2);
blackPen.Dispose();
}

------------------------------------------------------------------------------------------

Pen pen = new Pen(Color.Red);
e.Graphics.DrawLine(pen, 10, 50, 220, 50);
pen = new Pen(Color.Green, 2);
pen.DashStyle = DashStyle.DashDot;
e.Graphics.DrawLine(pen, 10, 80, 220, 80);
pen = new Pen(Brushes.DeepSkyBlue, 4);
e.Graphics.DrawLine(pen, 10, 120, 220, 120);
pen.Dispose();

---------------------------------------------------------------------------------

Pen[] objPen = new Pen[11];
for (int i = 0; i != 11; i++)
{
objPen[i] = new Pen(Color.Blue, 9);
}
objPen[0].EndCap = LineCap.AnchorMask;
objPen[2].EndCap = LineCap.ArrowAnchor;
objPen[3].EndCap = LineCap.DiamondAnchor;
objPen[4].EndCap = LineCap.Flat;
objPen[5].EndCap = LineCap.NoAnchor;
objPen[6].EndCap = LineCap.Round;
objPen[7].EndCap = LineCap.RoundAnchor;
objPen[8].EndCap = LineCap.Square;
objPen[9].EndCap = LineCap.SquareAnchor;
objPen[10].EndCap = LineCap.Triangle;
for (int i = 0; i != 11; i++)
{
e.Graphics.DrawLine(objPen[i], 10, 10+20*i, 200, 10+20*i);
objPen[i].Dispose();
}


-------------------------------------------------------------------------------

{
Pen pen = new Pen(Color.Green);
Point[] pt = {new Point(20,200), new Point(50,20),
new Point(100,100), new Point(150,20), new Point(200,200)
};
e.Graphics.DrawCurve(pen, pt);
pen.Dispose();

-----------------------------------------------------------------------------

{
GraphicsPath gp = new GraphicsPath();
gp.AddCurve(new Point[]
{
new Point(100,50),
new Point(105,40),
new Point(120,40),
new Point(130,65),
new Point(100,100)
}, 0.5f);
gp.AddCurve(new Point[]
{
new Point(100,100),
new Point(70,65),
new Point(80,40),
new Point(95,40),
new Point(100,50)
}, 0.5f);
e.Graphics.DrawPath(Pens.Red, gp);
}

----------------------------------------------------------------------

Pen mypen = new Pen(Color.Blue);
e.Graphics.DrawRectangle(mypen, 10, 120, 100, 100);
Rectangle rect = new Rectangle(10, 10, 100, 100);
e.Graphics.DrawRectangle(mypen, rect);



-------------------------------------------------------------------------


{
Pen curPen = new Pen(Color.Blue, 3);
Rectangle[] rect = { new Rectangle (20, 20, 120, 20),
new Rectangle (20, 50, 120, 30),
new Rectangle (20, 90, 120, 140),
new Rectangle (20, 140, 120, 60),
};
e.Graphics.DrawRectangles(curPen, rect);

----------------------------------------------------------

Rectangle rect = new Rectangle(10, 10, 120, 100);
e.Graphics.DrawEllipse(Pens.Cyan, rect);
Rectangle rect1 = new Rectangle(10, 120, 100, 100);
e.Graphics.FillEllipse(Brushes.DeepPink, rect1);
Rectangle rect2 = new Rectangle(150, 10, 120, 100);
e.Graphics.DrawEllipse(Pens.DarkSlateBlue, rect2);
Rectangle rect3 = new Rectangle(120, 120, 100, 100);
e.Graphics.FillEllipse(Brushes.Firebrick, rect3);

------------------------------------------------------------------

Pen penEllipse = new Pen(Color.Brown);
penEllipse.DashStyle = DashStyle.Dash;
e.Graphics.DrawEllipse(penEllipse, 20, 20, 200, 150);
Pen penArc = new Pen(Color.Magenta, 2);
e.Graphics.DrawArc(penArc, 20, 20, 200, 150, 45, 180);

-------------------------------------------------------------------------------------

Pen penEllipse = new Pen(Color.Brown);
penEllipse.DashStyle = DashStyle.Dash;
e.Graphics.DrawEllipse(penEllipse, 20, 20, 200, 150);
Pen penPie = new Pen(Color.Magenta, 2);
e.Graphics.DrawPie(penPie, 20, 20, 200, 150, 45, 90);
Pen penPie1 = new Pen(Color.BlueViolet, 2);
e.Graphics.DrawPie(penPie1, 20, 20, 200, 150, 135, 45);

-------------------------------------------------------------------------------

GraphicsPath gpath = new GraphicsPath();
gpath.AddEllipse(46, 4, 28, 28);
gpath.AddLine(36, 32, 84, 32);
gpath.AddLine(100, 80, 88, 84);
gpath.AddLine(76, 50, 74, 84);
gpath.AddLine(90, 150, 74, 84);
gpath.AddLine(60, 100, 46, 150);
gpath.AddLine(32, 150, 46, 84);
gpath.AddLine(44, 50, 32, 84);
gpath.AddLine(20, 80, 36, 32);
e.Graphics.FillPath(Brushes.Blue, gpath);










วันศุกร์ที่ 12 กรกฎาคม พ.ศ. 2556

LAB17 การเขียนโปรแกรมกราฟ

Graphics g = e.Graphics;
Pen bluepen = new Pen(Color.Blue,2);
g.DrawRectangle(bluepen, 10, 10, 100, 100);
bluepen.Dispose();

------------------------------------------------------------------------------------------------------

Graphics g = e.Graphics;
Pen bluepen = new Pen(Color.Blue,2);
g.DrawRectangle(bluepen, 10, 10, 100, 100);
bluepen.Dispose();
Pen somePen = new Pen(Color.FromArgb(255, 120, 200));
g.DrawEllipse(somePen, 20, 20, 200, 200);
somePen.Dispose();
----------------------------------------------------------------------------------------------

Graphics g = e.Graphics;
Pen bluepen = new Pen(Color.Blue,2);
g.DrawRectangle(bluepen, 10, 10, 100, 100);
bluepen.Dispose();
Pen somePen = new Pen(Color.FromArgb(255, 120, 200));
g.DrawEllipse(somePen, 20, 20, 200, 200);
somePen.Dispose();
Color col = Color.FromName("LightGreen");
this.BackColor = col;





--------------------------------------------------------------------------------------------

Graphics g = e.Graphics;
Pen mypen = new Pen(Color.Black, 1);
g.DrawRectangle(mypen, 10, 10, 200, 200);
mypen.Width = 4;
mypen.Color = Color.Pink;
g.DrawEllipse(mypen, 10, 10, 200, 200);

------------------------------------------------------------------------------------------------------

Graphics g = e.Graphics;
Pen mypen = new Pen(Color.Black, 1);
mypen.DashStyle = DashStyle.Dash;
g.DrawRectangle(mypen, 10, 10, 200, 200);
mypen.Width = 4;
mypen.Color = Color.Pink;
g.DrawEllipse(mypen, 10, 10, 200, 200);

---------------------------------------------------------------------------------------------

raphics g = e.Graphics;
HatchBrush myBrush = new HatchBrush(HatchStyle.DarkVertical, Color.White, Color.Violet);
Pen mypen = new Pen(myBrush, 5);
g.DrawEllipse(mypen, 10, 10, 200, 200);
mypen.Dispose();
myBrush.Dispose();

--------------------------------------------------------------------------------------------

Graphics g = e.Graphics;
HatchBrush myBrush = new HatchBrush(HatchStyle.DiagonalCross, Color.White, Color.Green);
Pen mypen = new Pen(myBrush, 5);
g.DrawEllipse(mypen, 10, 10, 200, 200);
mypen.Dispose();
myBrush.Dispose();











LAB16 การเพิ่ม progress control ใน Dialog based Application

CSliderCtrl *slider;
slider = (CSliderCtrl*) pScrollBar;
int pos = 0;
if(slider == &m_slider)
{
UpdateData(TRUE);
pos = m_slider.GetPos();
m_progress.SetPos(pos);
UpdateData(FALSE);



LAB15 การเพิ่ม slider control ใน Dialog based Application

SliderCtrl *slider;
slider = (CSliderCtrl*) pScrollBar;
if(slider == &m_slider)
{
UpdateData(TRUE);
m_value = m_slider1;
UpdateData(FALSE);
}
CDialog::OnHScroll(nSBCode, nPos, pScrollBar);





LAB14 การเพิ่ม spin button ใน Dialog based Application


m_spin.SetRange(1,100);
m_spin.SetBuddy(&m_edit);
m_spin.SetPos(1);

กดได้ถึง 100

----------------------------------------------------------------------------------------------

m_spin.SetRange(1,10);
m_spin.SetBuddy(&m_edit);
m_spin.SetPos(1);


กดได้ถึง 10

--------------------------------------------------------------------------------------------

m_spin.SetRange(1,10);
m_spin.SetBuddy(&m_edit);
m_spin.SetPos(1);
m_spin.SetBase(16);


LAB13 การเพิ่ม Combobox ใน Dialog based Application







void CLABBBBBBBB13Dlg::OnCbnSelchangeCombo1()
{
CString str;
int idx = m_comboBox1.GetCurSel();
if( idx < 0 )
return;
m_comboBox1.GetLBText( idx, str );
m_staticDestination.SetWindowText(str);
}

void CLABBBBBBBB13Dlg::OnBnClickedButtonAdd()
{

CString srcText;
m_editSource.GetWindowText(srcText);
m_comboBox1.AddString(srcText);

}

วันอาทิตย์ที่ 7 กรกฎาคม พ.ศ. 2556

LAB12 Wizard(Dialog Based) เพิ่มvariable



เมื่่อพิมพ์ตัวอักษรลงในช่องแรก ช่องที่สองและสาม ก็จะมีตัวอักษรเพิ่มขึ้นเหมือนที่พิมพ์

LAB11 Wizard(Dialog Based)




สร้างแบบ Dialog Based แล้ววางโค้ดลงไป จะได้ดังภาพ

void CMy11Dlg::OnBnClickedButton1()
{
MessageBox(_T("hello button1"));
}


void CMy11Dlg::OnBnClickedButton2()
{
MessageBox(_T("hello button2"));
}