tags:

views:

59

answers:

3

I am working on .NET 2.0 with C#. How to make focus the control to picture box after pressing the tab from text box ? Please, give me a solution.

+2  A: 

Picturebox control is not selectable control hence it doesn't receive focus. Even if you try to set tabindex and tabstop properties on form load it doesn't get the focus.

Why do you want to set focus to picturebox? Are you using click event of this control as a button click event?

Can you provide some more detail on this, so that we can provide a proper solution for this?

JPReddy
yes. I am using this picturebox with click event.
informative
I think it would be better to use button control with image property set to image and set flat style property to flat. This will make the button control look like a picture box and you can set tabindex property of that button as well. This is well suits your requirement if there is no specific reason to use picture box.
JPReddy
Yes. I done using button but the edges are not well look as in picturebox. That's why I choose picturebox.
informative
A: 

You need to enclose your PictureBox in a control that can receive click events.

egrunin
+1  A: 

Create a button1, then set its TabIndex less than pictureBox1's; put the button1 on top of pictureBox1. Then on runtime hide it behind pictureBox1. To give visual cue that pictureBox has the focus, set the BorderStyle to Fixed3d, set it to none when it loses focus.

Proof of concept:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TestPicture
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            button1.SendToBack();

            pictureBox1.Click += button1_Click;
        }

        private void button1_Enter(object sender, EventArgs e)
        {
            pictureBox1.BorderStyle = BorderStyle.Fixed3D;
        }

        private void button1_Leave(object sender, EventArgs e)
        {
            pictureBox1.BorderStyle = BorderStyle.None;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Test");
        }

    }
}
Michael Buen