niedziela, 23 października 2016

Simple Calendar in C++ Builder


void __fastcall TForm4::FormCreate(TObject *Sender)
{
 Edit1->Text=DateToStr(CCalendar1->CalendarDate);
}
//---------------------------------------------------------------------------
void __fastcall TForm4::Button1Click(TObject *Sender)
{
 Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm4::CCalendar1Change(TObject *Sender)
{
 Caption="Year-Month-Day  "+DateToStr(CCalendar1->CalendarDate);
}
//---------------------------------------------------------------------------
void __fastcall TForm4::Button2Click(TObject *Sender)
{
 CCalendar1->PrevYear();
}
//---------------------------------------------------------------------------
void __fastcall TForm4::Button3Click(TObject *Sender)
{
 CCalendar1->PrevMonth();
}
//---------------------------------------------------------------------------
void __fastcall TForm4::Button4Click(TObject *Sender)
{
 CCalendar1->NextYear();
}
//---------------------------------------------------------------------------
void __fastcall TForm4::Button5Click(TObject *Sender)
{
 CCalendar1->NextMonth();
}

piątek, 21 października 2016

Visual C++ drawing triangle or ellipse in 8 colors


#pragma endregion
private: Graphics^ g;
private: Pen^ my_pen1;
Pen^ my_pen2;
Pen^ my_pen3;
Pen^ my_pen4;
Pen^ my_pen5;
Pen^ my_pen6;
Pen^ my_pen7;
Pen^ my_pen8;
private: System::Void init_Graphics()
{
g=panel1->CreateGraphics();
my_pen1=gcnew Pen(System::Drawing::Color::Red);
my_pen2=gcnew Pen(System::Drawing::Color::Brown);
my_pen3=gcnew Pen(System::Drawing::Color::Green);
my_pen4=gcnew Pen(System::Drawing::Color::Lime);
my_pen5=gcnew Pen(System::Drawing::Color::Purple);
my_pen6=gcnew Pen(System::Drawing::Color::Blue);
my_pen7=gcnew Pen(System::Drawing::Color::Black);
my_pen8=gcnew Pen(System::Drawing::Color::Orange);
}
private: System::Void draw_Triangle(int x1,int y1, int x2, int y2, int x3, int y3, Pen ^pen)
 {
 g->DrawLine(pen,x1,y1,x2,y2);
 g->DrawLine(pen,x2,y2,x3,y3);
 g->DrawLine(pen,x3,y3,x1,y1);
 }
 private: System::Void draw_Ellipse(int x, int y, int width, int height, Pen ^pen)
  {
  g->DrawEllipse(pen,x,y,width,height);
  }
 

private: System::Void init_Random()
{
srand(time(NULL));
}
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
Close();
}
private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
init_Random();
}
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
init_Graphics();
 
int i,j,k;
System::Int32 how_many;
int x1,y1,x2,y2,x3,y3;
int x_ellipse,y_ellipse,w,h;
how_many=Int32::Parse(textBox1->Text);
for(i=0;i<how_many;i++)
{
                     k=rand()%2;
if(k==0)
{
                      j=rand()%8;
 switch(j)
 {
 case 0: x_ellipse=panel1->Width/8+rand()%100,y_ellipse=panel1->Height/8+rand()%100,w=1+rand()%panel1->Width,h=1+rand()%panel1->Height;
     draw_Ellipse(x_ellipse,y_ellipse,w,h,my_pen1);break;
 case 1: x_ellipse=panel1->Width/8+rand()%100,y_ellipse=panel1->Height/8+rand()%100,w=1+rand()%panel1->Width,h=1+rand()%panel1->Height;
     draw_Ellipse(x_ellipse,y_ellipse,w,h,my_pen2);break;
 case 2: x_ellipse=panel1->Width/8+rand()%100,y_ellipse=panel1->Height/8+rand()%100,w=1+rand()%panel1->Width,h=1+rand()%panel1->Height;
     draw_Ellipse(x_ellipse,y_ellipse,w,h,my_pen3);break;
 case 3: x_ellipse=panel1->Width/8+rand()%100,y_ellipse=panel1->Height/8+rand()%100,w=1+rand()%panel1->Width,h=1+rand()%panel1->Height;
     draw_Ellipse(x_ellipse,y_ellipse,w,h,my_pen4);break;
 case 4: x_ellipse=panel1->Width/8+rand()%100,y_ellipse=panel1->Height/8+rand()%100,w=1+rand()%panel1->Width,h=1+rand()%panel1->Height;
     draw_Ellipse(x_ellipse,y_ellipse,w,h,my_pen5);break;
 case 5: x_ellipse=panel1->Width/8+rand()%100,y_ellipse=panel1->Height/8+rand()%100,w=1+rand()%panel1->Width,h=1+rand()%panel1->Height;
     draw_Ellipse(x_ellipse,y_ellipse,w,h,my_pen6);break;
 case 6: x_ellipse=panel1->Width/8+rand()%100,y_ellipse=panel1->Height/8+rand()%100,w=1+rand()%panel1->Width,h=1+rand()%panel1->Height;
     draw_Ellipse(x_ellipse,y_ellipse,w,h,my_pen7);break;
 case 7: x_ellipse=panel1->Width/8+rand()%100,y_ellipse=panel1->Height/8+rand()%100,w=1+rand()%panel1->Width,h=1+rand()%panel1->Height;
     draw_Ellipse(x_ellipse,y_ellipse,w,h,my_pen8);break;
 }
}
else
{
j=rand()%8;
switch(j)
{
case 0: x1=1+rand()%panel1->Width-1;x2=x1=1+rand()%panel1->Width-1;x3=x1=1+rand()%panel1->Width-1;y1=1+rand()%panel1->Height-1;y2=1+rand()%panel1->Height-1;
y3=1+rand()%panel1->Height-1;draw_Triangle(x1,y1,x2,y2,x3,y3,my_pen1);break;
case 1: x1=1+rand()%panel1->Width-1;x2=x1=1+rand()%panel1->Width-1;x3=x1=1+rand()%panel1->Width-1;y1=1+rand()%panel1->Height-1;y2=1+rand()%panel1->Height-1;
y3=1+rand()%panel1->Height-1;draw_Triangle(x1,y1,x2,y2,x3,y3,my_pen2);break;
case 2: x1=1+rand()%panel1->Width-1;x2=x1=1+rand()%panel1->Width-1;x3=x1=1+rand()%panel1->Width-1;y1=1+rand()%panel1->Height-1;y2=1+rand()%panel1->Height-1;
y3=1+rand()%panel1->Height-1;draw_Triangle(x1,y1,x2,y2,x3,y3,my_pen3);break;
case 3: x1=1+rand()%panel1->Width-1;x2=x1=1+rand()%panel1->Width-1;x3=x1=1+rand()%panel1->Width-1;y1=1+rand()%panel1->Height-1;y2=1+rand()%panel1->Height-1;
y3=1+rand()%panel1->Height-1;draw_Triangle(x1,y1,x2,y2,x3,y3,my_pen4);break;
case 4: x1=1+rand()%panel1->Width-1;x2=x1=1+rand()%panel1->Width-1;x3=x1=1+rand()%panel1->Width-1;y1=1+rand()%panel1->Height-1;y2=1+rand()%panel1->Height-1;
y3=1+rand()%panel1->Height-1;draw_Triangle(x1,y1,x2,y2,x3,y3,my_pen5);break;
case 5: x1=1+rand()%panel1->Width-1;x2=x1=1+rand()%panel1->Width-1;x3=x1=1+rand()%panel1->Width-1;y1=1+rand()%panel1->Height-1;y2=1+rand()%panel1->Height-1;
y3=1+rand()%panel1->Height-1;draw_Triangle(x1,y1,x2,y2,x3,y3,my_pen6);break;
case 6: x1=1+rand()%panel1->Width-1;x2=x1=1+rand()%panel1->Width-1;x3=x1=1+rand()%panel1->Width-1;y1=1+rand()%panel1->Height-1;y2=1+rand()%panel1->Height-1;
y3=1+rand()%panel1->Height-1;draw_Triangle(x1,y1,x2,y2,x3,y3,my_pen7);break;
case 7: x1=1+rand()%panel1->Width-1;x2=x1=1+rand()%panel1->Width-1;x3=x1=1+rand()%panel1->Width-1;y1=1+rand()%panel1->Height-1;y2=1+rand()%panel1->Height-1;
y3=1+rand()%panel1->Height-1;draw_Triangle(x1,y1,x2,y2,x3,y3,my_pen8);break;

}
 }
}
 
}
private: System::Void textBox1_TextChanged(System::Object^  sender, System::EventArgs^  e) {
}
};
}


niedziela, 16 października 2016

Testing C++ Builder 10.1 Berlin Starter

I was downloading C++ Builder 10.1 Berlin Starter, before was used C++ Builder 6 Personal.



void __fastcall TForm4::Frame()
{
int margin=5;
int width=PaintBox1->Width-margin;
int height=PaintBox1->Height-margin;
PaintBox1->Canvas->Pen->Color=clGreen;
PaintBox1->Canvas->MoveTo(margin,margin);
PaintBox1->Canvas->LineTo(width,margin);
PaintBox1->Canvas->LineTo(width,height);
PaintBox1->Canvas->LineTo(margin,height);
PaintBox1->Canvas->LineTo(margin,margin);
}
void __fastcall TForm4::Diagonals()
{
int margin=5;
int width=PaintBox1->Width-margin;
int height=PaintBox1->Height-margin;
PaintBox1->Canvas->MoveTo(margin,margin);
PaintBox1->Canvas->LineTo(width,height);
PaintBox1->Canvas->MoveTo(width,margin);
PaintBox1->Canvas->LineTo(margin,height);
}
void __fastcall TForm4::Cross()
{
  int margin=5;
  int width=PaintBox1->Width-margin;
  int height=PaintBox1->Height-margin;
  int my_width=width/2;
  int my_height=height/2;
  PaintBox1->Canvas->Pen->Color=clRed;
  PaintBox1->Canvas->MoveTo(margin,my_height);
  PaintBox1->Canvas->LineTo(width,my_height);
  PaintBox1->Canvas->MoveTo(my_width,margin);
  PaintBox1->Canvas->LineTo(my_width,height);

}
void __fastcall TForm4::Circles()
{
int centrum_x=PaintBox1->Width/2;
int centrum_y=PaintBox1->Height/2;
int value=30;
PaintBox1->Canvas->Ellipse(centrum_x,centrum_y,value,value);
PaintBox1->Canvas->Ellipse(centrum_x,centrum_y,2*centrum_x-value,2*centrum_y-value);

}
void __fastcall TForm4::Rectangles()
{
  int centrum_x=PaintBox1->Width/2;
  int centrum_y=PaintBox1->Height/2;
  int value=60;
  PaintBox1->Canvas->Brush->Color=clYellow;
  PaintBox1->Canvas->Rectangle(value,centrum_y,centrum_x-value,2*centrum_y-value);
  PaintBox1->Canvas->Rectangle(centrum_x+value,value,2*centrum_x-value,centrum_y);
}

void __fastcall TForm4::Text()
{
int value=40;
int x_north=PaintBox1->Width/2;
int y_north=value;
int x_east=PaintBox1->Width-value;
int y_east=PaintBox1->Height/2;
int x_south=PaintBox1->Width/2;
int y_south=PaintBox1->Height-value;
int x_west=value;
int y_west=PaintBox1->Height/2;
PaintBox1->Canvas->Brush->Color=clWhite;
PaintBox1->Canvas->TextOutW(x_north,y_north,"North");
PaintBox1->Canvas->TextOutW(x_east,y_east,"East");
PaintBox1->Canvas->TextOutW(x_south,y_south,"South");
PaintBox1->Canvas->TextOutW(x_west,y_west,"West");

}
void __fastcall TForm4::Button1Click(TObject *Sender)
{
 Close();
}
//---------------------------------------------------------------------------

void __fastcall TForm4::Button2Click(TObject *Sender)
{
 Frame();
 Diagonals();
 Cross();
 Circles();
 Rectangles();
 Text();

}
//---------------------------------------------------------------------------


poniedziałek, 3 października 2016

Create new files with new names and writes in Visual C++


Result:

private: System::Void init_Random()
{
srand(time(NULL));
}
private: System::Char my_Lowercase()
{
int x,j=1;;
char i;
x=rand()%26;
i='a';
for(j=0;j<=x-1;j++)
{
i++;
}

return i;

}
private: System::Char my_Uppercase()
{
int x,j=1;
char i;
i='A';
x=rand()%26;
for(j=0;j<=x-1;j++)
{
i++;
}

return i;

}
private: System::Char case_ListBox()
 {
 int i;
 i=rand()%2;
 if(i==1)
 return my_Uppercase();
 else
 return my_Lowercase();
 }
 private: System::Int16 my_Number()
  {
  int x;
  x=rand()%10;
  return x;
  }
private: System::String^ symbol_ListBox()
 {
 int i;
 i=rand()%2;
 if(i==1)
 return case_ListBox().ToString();
 else
 return my_Number().ToString();
 }
private: System::Void clear_ListBoxes()
 {
               listBox1->Items->Clear();
  listBox2->Items->Clear();
  listBox3->Items->Clear();
  listBox4->Items->Clear();
  listBox5->Items->Clear();

 }
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
Close();
}
private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
 
init_Random();
timer1->Start();
}
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
int i;
int j,how_many;
 
how_many=Convert::ToInt16(textBox1->Text);
array <System::String^>^ my_string=gcnew array<System::String^>(how_many);
clear_ListBoxes();
for(i=0;i<how_many;i++)
{
listBox1->Items->Add(case_ListBox().ToString());
listBox2->Items->Add(symbol_ListBox());
listBox3->Items->Add(case_ListBox().ToString());
listBox4->Items->Add(symbol_ListBox());
my_string[i]=listBox1->Items[i]->ToString()+listBox2->Items[i]->ToString()+listBox3->Items[i]->ToString()+listBox4->Items[i]->ToString()+".txt";
listBox5->Items->Add(my_string[i]);
}
i=0;
do
{
 StreamWriter^ my_stream = gcnew StreamWriter(my_string[i]);
 my_stream->Write(label7->Text);
     my_stream->Close();
 i++;
}while(i<how_many);

}
private: System::Void timer1_Tick(System::Object^  sender, System::EventArgs^  e) {
DateTime my_time=DateTime::Now;
label7->Text="  time "+my_time.Hour.ToString("D2")+":"+my_time.Minute.ToString("D2")+":"+my_time.Second.ToString()+
" date "+my_time.Day.ToString()+"-"+my_time.Month.ToString()+"-"+my_time.Year.ToString();
}
private: System::Void Form1_FormClosing(System::Object^  sender, System::Windows::Forms::FormClosingEventArgs^  e) {
timer1->Stop();
}
};



}