niedziela, 4 września 2016

Graphics^ in Visual C++

I wanted to recall the graphics methods in Visual C++.



#pragma endregion
private:
System::Void init_Random()
{
srand(time(NULL));
}
private:
Graphics^ my_graph;
Pen^ my_pen1;
Pen^ my_pen2;
Pen^ my_pen3;
Pen^ my_pen4;
Pen^ my_pen5;
Pen^ my_pen6;
private:
System::Drawing::Color color1;
System::Drawing::Color color2;
System::Drawing::Color color3;
System::Drawing::Color color4;
System::Drawing::Color color5;
System::Drawing::Color color6;
private:
System::Void init_Graph()
{
my_graph=panel1->CreateGraphics();
color1=System::Drawing::Color::Yellow;
color2=System::Drawing::Color::Blue;
color3=System::Drawing::Color::Red;
color4=System::Drawing::Color::White;
color5=System::Drawing::Color::Violet;
color6=System::Drawing::Color::Green;
my_pen1=gcnew Pen(color1);
my_pen2=gcnew Pen(color2);
my_pen3=gcnew Pen(color3);
my_pen4=gcnew Pen(color4);
my_pen5=gcnew Pen(color5);
my_pen6=gcnew Pen(color6);


}
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
Close();
}
private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
init_Graph();
init_Random();
}
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
int centr_x,centr_y,marg=5,i,j;
centr_x=panel1->Width/2;
centr_y=panel1->Height/2;
//frame
my_pen1->Width=3;
my_pen1->DashStyle=System::Drawing::Drawing2D::DashStyle::DashDot;
my_graph->DrawLine(my_pen1,marg,marg,panel1->Width-marg,marg);
my_graph->DrawLine(my_pen1,marg,panel1->Height-marg,panel1->Width-marg,panel1->Height-marg);
my_graph->DrawLine(my_pen1,marg,marg,marg,panel1->Height-marg);
my_graph->DrawLine(my_pen1,panel1->Width-marg,marg,panel1->Width-marg,panel1->Height-marg);
my_pen2->Width=2;
my_pen2->StartCap=System::Drawing::Drawing2D::LineCap::Square;
my_pen2->EndCap=System::Drawing::Drawing2D::LineCap::Round;
my_graph->DrawLine(my_pen2,centr_x,marg,centr_x,panel1->Height-marg);
my_graph->DrawLine(my_pen2,marg,centr_y,panel1->Width-marg,centr_y);
my_pen3->Width=3;
j=30;
    for(i=0;i<4;i++)
{
  my_graph->DrawEllipse(my_pen3,centr_x-j,centr_y-j,j*2,j*2);
  j+=30;
}
Bitmap^ my_bitmap=gcnew Bitmap(panel1->Width,panel1->Height);
System::Drawing::Color temp_color;
for(i=marg;i<panel1->Width-marg;i+=marg)
{
for(j=marg;j<panel1->Height;j+=marg)
{
temp_color=System::Drawing::Color::FromArgb(rand()%255,rand()%255,rand()%255);
my_bitmap->SetPixel(i,j,temp_color);
}
}
my_graph->DrawImage(dynamic_cast<Image^>(my_bitmap),1,1);
my_pen4->Width=5;
my_pen4->StartCap=System::Drawing::Drawing2D::LineCap::RoundAnchor;
my_pen4->EndCap=System::Drawing::Drawing2D::LineCap::ArrowAnchor;
my_pen4->DashStyle=System::Drawing::Drawing2D::DashStyle::DashDot;
my_graph->DrawLine(my_pen4,centr_x,marg,panel1->Width-marg,centr_y);
my_graph->DrawLine(my_pen4,panel1->Width-marg,centr_y,centr_x,panel1->Height-marg);
my_graph->DrawLine(my_pen4,centr_x,panel1->Height-marg,marg,centr_y);
my_graph->DrawLine(my_pen4,marg,centr_y,centr_x,marg);

int x,y,a,h;
x=30,y=30,a=60,h=60;
my_pen5->Width=3;
my_graph->DrawEllipse(my_pen5,x,y,a,h);
x=30,y=panel1->Height-90;
my_graph->DrawEllipse(my_pen5,x,y,a,h);
x=panel1->Width-90,y=30,a=60,h=60;
my_graph->DrawEllipse(my_pen5,x,y,a,h);
y=panel1->Height-90;
my_graph->DrawEllipse(my_pen5,x,y,a,h);
my_pen6->Width=4;
my_pen6->DashCap=System::Drawing::Drawing2D::DashCap::Round;
my_pen6->DashStyle=System::Drawing::Drawing2D::DashStyle::DashDotDot;
my_graph->DrawLine(my_pen6,marg,marg,panel1->Width-marg,panel1->Height-marg);
my_graph->DrawLine(my_pen6,panel1->Width-marg,marg,marg,panel1->Height-marg);


}
};
}

Brak komentarzy:

Prześlij komentarz