6. Focus Method
• We sometimes use the following
private: System::Void button1_Click_3(System::Object^
System::EventArgs^ e)
{
if (textBox2->CanFocus == true )
{
textBox2->Focus() ;
}
}
sender,
• Why? And what will happen?
Cause some controlls don’t have the Focus method as one of
their members
8. 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)
9. Focus Method
public: void ControlSetFocus(Control^ control)
{
// Set focus to the control, if it can receive focus.
if (control->CanFocus)
control->Focus();
}
20. 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();
}
53. 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 ;
}
}
57. 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;
}