�@Windows�t�H�[���ŃX���b�h���쐬�����ꍇ�A�t�H�[����t�H�[����̃R���g���[���ɑ��ẮA���̃X���b�h����̑���i�t�H�[����R���g���[���������\�b�h�̌Ăяo����v���p�e�B�̓ǂݏ����j�͓��삪�ۏ���Ȃ��B�{�e�ł͂��̂悤�ȏ����������S���ɍs�����߂̃v���O���~���O�ɂ��ĉ������B
�@�Ⴆ�AVisual Studio .NET�i�ȍ~�AVS.NET�j��Windows�A�v���P�[�V�����̃v���W�F�N�g��V�K�쐬���A���̉�ʂ̂悤�ɁA2�̃e�L�X�g�{�b�N�X�iTextBox1��TextBox2�j��1�̃{�^���iButton1�j��z�u�����Ƃ���B
�@���̃A�v���P�[�V���������s����ƁA�N�����ɂ̓t�H�[�J�X��TextBox1�ɐݒ肳���B���ɁA�{�^�����N���b�N���ꂽ�Ƃ��ɁATextBox2�Ƀt�H�[�J�X���ݒ肳���悤�ɂ��Ă݂悤�B
�@����ɂ�VS.NET��Ŕz�u�����{�^�����_�u���N���b�N���A����ɂ�萶�����ꂽ�C�x���g�E�n���h���Ɏ��̂悤�ȃR�[�h���L�q����悢�B
private void button1_Click(object sender, System.EventArgs e)
{
textBox2.Focus();
}
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox2.Focus()
End Sub
�@Focus���\�b�h�͂��̃R���g���[���Ƀt�H�[�J�X��ݒ肷�邽�߂̂��̂��B���R�Ȃ���A���̃R�[�h�͐��������s�����B
�@���ɁA�{�^�����N���b�N���ꂽ�Ƃ��ɃX���b�h���N�����A���̃X���b�h��Focus���\�b�h���Ăяo���Ă݂�B���̃R�[�h�͈ȉ��̂悤�ɂȂ�B
private void button1_Click(object sender, System.EventArgs e)
{
Thread t = new Thread(new ThreadStart(worker));
t.Start();
}
void worker()
{
textBox2.Focus(); // ������Ăяo��
}
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim t As New Thread(New ThreadStart(AddressOf worker))
t.Start()
End Sub
Sub worker()
TextBox2.Focus() ' ������Ăяo��
End Sub
�@���̃R�[�h�ł́Abutton1_Click���\�b�h�̓R���g���[�����쐬���ꂽ�X���b�h�i�ȉ��A���C���E�X���b�h�j�Ŏ��s�����̂ɑ��āAworker���\�b�h�͕ʃX���b�h�Ŏ��s�����B���̂��߁Aworker���\�b�h���ŌĂяo���Ă���TextBox2��Focus���\�b�h�̎��s�́A���̓��삪�ۏ���Ȃ��B���ۂɃv���O���������s���{�^�����N���b�N���Ă��t�H�[�J�X�͈ړ����Ȃ��͂����B
�@Control�N���X�iSystem.Windows.Forms���O��ԁj�ɂ́A�ʃX���b�h����R���g���[���𑀍삷��ꍇ�Ɏg�p�ł���Invoke���\�b�h���p�ӂ���Ă���i�t�H�[�����n�߂Ƃ��邷�ׂẴR���g���[���͂��̃��\�b�h���p�����Ă���j�BInvoke���\�b�h���g���ƁA�R���g���[���ɑ��鑀������C���E�X���b�h�Ŏ��s�����邱�Ƃ��ł���B
�@��̓I�ɂ́A���C���E���\�b�h��Ŏ��s���������\�b�h�i�R���g���[���ւ̑�����܂ށj�ɑΉ������f���Q�[�g���쐬���A���̃f���Q�[�g�̃C���X�^���X��Invoke���\�b�h�̃p�����[�^�Ŏw�肵�ČĂяo���悢�BInvoke���\�b�h���R���g���[���������\�b�h�ł��邪�A���̌Ăяo���͕ʃX���b�h����ł����삪�ۏ���Ă���B
�@���̃R�[�h�́A��L�̌�����R�[�h��Invoke���\�b�h���g���ď������������̂��B
private void button1_Click(object sender, System.EventArgs e)
{
Thread t = new Thread(new ThreadStart(worker));
t.Start();
}
delegate bool FocusDelegate();
void worker()
{
// textBox2.Focus()�̎��s
Invoke(new FocusDelegate(textBox2.Focus));
}
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim t As New Thread(New ThreadStart(AddressOf worker))
t.Start()
End Sub
Delegate Function FocusDelegate() As Boolean
Sub worker()
' textBox2.Focus()�̎��s
Invoke(New FocusDelegate(AddressOf TextBox2.Focus))
End Sub
�@���̃R�[�h�ł́ATextBox2��Focus���\�b�h�����C���E�X���b�h��Ŏ��s����邽�߁A�v���O�����͐��������삷��B
�@�Ȃ���L�̃R�[�h�ł́A�e�L�X�g�{�b�N�X��Focus���\�b�h�ɑ��ăf���Q�[�g���쐬���Ă��邪�A�ʏ�͎��̂悤�Ƀ��\�b�h��1�쐬���i���̏ꍇ�ɂ�SetFocus���\�b�h�j�A������f���Q�[�g�o�R�ŌĂяo���悤�ɂ���̂���ʓI���B
private void button1_Click(object sender, System.EventArgs e)
{
Thread t = new Thread(new ThreadStart(worker));
t.Start();
}
delegate void SetFocusDelegate();
void SetFocus()
{
textBox2.Focus();
}
void worker()
{
Invoke(new SetFocusDelegate(SetFocus));
}
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim t As New Thread(New ThreadStart(AddressOf worker))
t.Start()
End Sub
Delegate Sub SetFocusDelegate()
Sub SetFocus()
TextBox2.Focus()
End Sub
Sub worker()
Invoke(New SetFocusDelegate(AddressOf SetFocus))
End Sub
�@Control�N���X�ɂ́AInvoke���\�b�h���g���K�v�����邩�ǂ������`�F�b�N���邽�߂�InvokeRequired�v���p�e�B���p�ӂ���Ă���B���̃v���p�e�B�́A������Ăяo�����X���b�h�����C���E�X���b�h���ǂ����ׁAtrue���邢��false��Ԃ��B
�@���̃R�[�h�́A��L�̃R�[�h��InvokeRequired�v���p�e�B�𗘗p���ď������������̂��B���̃R�[�h��SetFocus���\�b�h�́A���C���E�X���b�h����ł��ʃX���b�h����ł��Ăяo�����Ƃ��ł���悤�ɂȂ��Ă���i�ʃX���b�h����SetFocus���\�b�h���Ăяo�����ꍇ�ɂ́A���ʓI��SetFocus���\�b�h��2�x���s����邱�ƂɂȂ�j�B
private void button1_Click(object sender, System.EventArgs e)
{
Thread t = new Thread(new ThreadStart(worker));
t.Start();
}
delegate void SetFocusDelegate();
void SetFocus()
{
if (InvokeRequired)
{
// �ʃX���b�h����Ăяo���ꂽ�ꍇ
Invoke(new SetFocusDelegate(SetFocus));
return;
}
textBox2.Focus();
}
void worker()
{
SetFocus();
}
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim t As New Thread(New ThreadStart(AddressOf worker))
t.Start()
End Sub
Delegate Sub SetFocusDelegate()
Sub SetFocus()
If InvokeRequired Then
' �ʃX���b�h����Ăяo���ꂽ�ꍇ
Invoke(New SetFocusDelegate(AddressOf SetFocus))
Return
End If
TextBox2.Focus()
End Sub
Sub worker()
SetFocus()
End Sub
�@�����X���b�h���ł����Ă��AInvoke���\�b�h�𗘗p�����R���g���[���̑���͓��ɖ��Ȃ��Ǝv���邪�A����X���b�h����̃R���g���[���̑����Invoke���\�b�h�ōs���͖̂��ʂł���BInvokeRequired�v���p�e�B���g���A���̂悤�Ȗ��ʂȏ������Ȃ����Ƃ��ł���B
�J�e�S���F�N���X�E���C�u�����@�����ΏہF�R���g���[��
�J�e�S���F�N���X�E���C�u�����@�����ΏہF�}���`�X���b�h
�g�p���C�u�����FControl�N���X�iSystem.Windows.Forms���O��ԁj
�g�p���C�u�����FThread�N���X�iSystem.Threading���O��ԁj
�u.NET TIPS�v
Copyright© Digital Advantage Corp. All Rights Reserved.
��IT eBook
�ҏW������̂��m�点