Upload
mohammad-shaker
View
210
Download
4
Embed Size (px)
DESCRIPTION
C++ Windows Forms L05 - Controls P4 of C++ Windows Forms Light Course
Citation preview
Mohammad Shakermohammadshakergtr.wordpress.com
C++.NET Windows Forms Course@ZGTRShaker
C++.NET Windows Forms Course
L05 -Controls Part 4
Focus Method
Focus Method
• What will happen now? private: System::Void button1_Click_3(System::Object^ sender,
System::EventArgs^ e)
{
textBox2->Focus() ;
}
Focus Method
After clicking button1Before clicking button1
Focus Method
• We sometimes use the following
• Why? And what will happen? Cause some controlls don’t have the Focus method as one of
their members
private: System::Void button1_Click_3(System::Object^ sender,
System::EventArgs^ e)
{
if (textBox2->CanFocus == true )
{
textBox2->Focus() ;
}
}
Focus Method
After clicking button1Before clicking button1
Focus Method
• The Windows Forms controls in the following list are not selectable. Controls derived from these controls are also not selectable.
• Panel• GroupBox• PictureBox• ProgressBar• Splitter• Label• LinkLabel (when there is no link present in the control)
Focus Method
public: void ControlSetFocus(Control^ control)
{
// Set focus to the control, if it can receive focus.
if (control->CanFocus)
control->Focus();
}
DataGridVeiw
DataGridVeiw
• Matrix• DataBase• DataBind (DataSource)
DataGridVeiw
DataGridVeiw
• Dock in parent container
DataGridVeiw
DataGridVeiw
DataGridVeiw
DataGridVeiw
private: System::Void button1_Click_1(System::Object^ sender,
System::EventArgs^ e)
{
dataGridView1[0,0]->Value = 3;
}
DataGridVeiw
• Is it the same with columns? No need to!
private: System::Void button1_Click_1(System::Object^ sender,
System::EventArgs^ e)
{
textBox1->Text=dataGridView1->Rows[0]->Cells[1]->Value-> ToString();
}
DataGridVeiw
StatusBar
StatusBar
StatusBar
StatusBar
StatusBar
StatusBar
• Can add more than one!
StatusBar
• Let’s have the following …
StatusBar
private: System::Void button1_Click_5(System::Object^ sender,
System::EventArgs^ e)
{
toolStripStatusLabel1->Text = "You are clicking the button and you
seem hungy:D";
}
StatusBar
Before clicking button1 After clicking button1
StatusBar
• What will happen now? private: System::Void Form1_MouseMove(System::Object^ sender,
System::Windows::Forms::MouseEventArgs^ e)
{
toolStripProgressBar1->PerformStep();
}
MenuStrip
MenuStrip - Runtime
Has Events Like any other
Timer
Timer
Timer
• Consider this:
• What should happen now?
private: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e)
{
timer1->enabled = true;
}
private: System::Void timer1_Tick(System::Object^ sender,
System::EventArgs^ e)
{
progressBar1->PerformStep();
}
Timer
• Before clicking the “start” button
Timer
• After clicking the “start” button
Quick App
OpenFileDialog
OpenFileDialog
private: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e)
{
openFileDialog1->ShowDialog();
}
OpenFileDialog
OpenFileDialog
• Note that openFileDialog won’t open any file! Just a dialog!private: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e)
{
if (openFileDialog1->ShowDialog()==(System::Windows::Forms::DialogResult::OK))
{
textBox1->Text = openFileDialog1->FileName ;
}
}
OpenFileDialogprivate: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e)
{
if(
openFileDialog1->ShowDialog()==(System::Windows::Forms::DialogResult::OK))
{
textBox1->Text = openFileDialog1->FileName ;
openFileDialog1->ShowReadOnly = true ;
}
}
OpenFileDialog
OpenFileDialog - Filters
• text files (*.txt) |*.txt• All files (*.*) | *.*
OpenFileDialog - Folders// If a file is not opened then set the initial directory to the// FolderBrowserDialog::SelectedPath value.if ( !fileOpened ){
openFileDialog1->InitialDirectory = folderBrowserDialog1->SelectedPath;openFileDialog1->FileName = nullptr;
}
SaveFileDialog
OpenFileDialog
private:void button1_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ ){
Stream^ myStream;OpenFileDialog^ openFileDialog1 = gcnew OpenFileDialog;
openFileDialog1->InitialDirectory = "c:\\";openFileDialog1->Filter = "txt files (*.txt)|*.txt|All files
(*.*)|*.*";openFileDialog1->FilterIndex = 2;openFileDialog1->RestoreDirectory = true;
if ( openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK )
{if ( (myStream = openFileDialog1->OpenFile())!= nullptr ){
// Insert code to read the stream here.myStream->Close();
}}
}
using namespace System::IO;
SaveFileDialog
private:
void button1_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
Stream^ myStream;
SaveFileDialog^ saveFileDialog1 = gcnew SaveFileDialog;
saveFileDialog1->Filter = "txt files (*.txt)|*.txt|All files
(*.*)|*.*";
saveFileDialog1->FilterIndex = 2;
saveFileDialog1->RestoreDirectory = true;
if ( saveFileDialog1->ShowDialog() ==
System::Windows::Forms::DialogResult::OK)
{
if ( (myStream = saveFileDialog1->OpenFile())!= nullptr)
{
// Code to write the stream goes here.
myStream->Close();
}
}
}
using namespace System::IO;
That’s it for today!