thanks
- mike
/*something here*/
this.Focus();
David M. Kean wrote:
What has the focus if the MainForm doesn't?<br /><br />Can you post some small code that reproduces it here?
namespace MainFormNamespace
{
public delegate void OpenNewDialogEvent();
public class MainForm : System.Windows.Forms.Form
{
private System.ComponentModel.Container components = null;
private treeViewEnhanced treeView;
public MainForm()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
private void InitializeComponent()
{
this.treeView = new treeViewEnhanced();
this.SuspendLayout();
this.treeView.OpenNewDialog += new OpenNewEventDialog(OpenNewDialog);
this.ResumeLayout(false);
}
private void OpenNewDialog()
{
Form NewDialog = new Form();
NewDialog.ShowDialog();
this.Focus();
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new MainForm());
}
}
public class treeViewEnhanced : System.Windows.Forms.TreeView
{
private System.ComponentModel.Container components = null;
public event OpenNewDialogEvent OpenNewDialog;
public treeViewEnhanced()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.FillRectangle(new SolidBrush(System.Drawing.Color.Olive), new Rectangle(0, 0, 100, 100));
}
protected override void OnMouseDown(MouseEventArgs e)
{
if (e.Clicks == 2)
{
if (e.X >= 0 && e.X <= 100 && e.Y >= 0 && e.Y <= 100)
OpenNewDialog();
}
this.Invalidate();
}
}
}
As I've already stated, if once-clicking is used, then everything is normal.
I didn't put in the code various event handlers (as leave, enter, mouseleave, etc.), as I tried everything and nothing worked properly.
truetype
It seems to be that you are interrupting the mouse processing (by showing a dialog on MouseDown) and causing focus issues.
I found that you could achieve the same thing (without the focus issue), by overridding OnDoubleClick or OnMouseDoubleClick methods instead of the OnMouseDown method. However, these events are only raised when a TreeNode is double-clicked.
truetype