I am sure its simple, but I have searched about and can't seem to et something working.
Simple window, i created a panel in.
Here is what I have and have tried: The commented portions are what I have tried.
[code]
private
: System::Void IrrlichtPanel_Paint_1(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e){
ObjDisplay->init((s32)
this->MyPanel->Handle.ToPointer()); //this->MyPanel->BringToFront();//MyPanel->BringToFront();
//this->MyPanel->Focus();
MyPanel->Focus();
}
[/code]
The object I am loading into the panel is displaying correctly, however it needs to have focus for keyboard input, but I just can't seem to get it.

giving a panel focus
Duane Douglas
You need to call gcnew to create new managed objects.
ivanL
Bingo.
Thanks for bearing with me - and sorry, I should've mentioned Managed C++
thmccarthy
Anil Kumar29
You should set focus to the object itself:
TextBox txtInput = new TextBox();
....
MyPanel.Controls.Add(txtInput);
....
txtInput->Focus();
Craig0111
Ah. I see. This is making sense.
However, I am still hitting 2 errors (can you tell who is new to this )
Here is what I did:
Add->New Item->Windows Form
I named my new form "frmChildTest"
Then in "Form1.h" (the parent):
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e)
{
Form frm = new frmChildTest(); frm.TopLevel = false;
frm.Parent = this;
frm.Show();
}
and I am getting the errors:
'ModelEditor::frmChildTest' : cannot use 'new' on the reference type; use 'gcnew' instead
'System::Windows::Forms::Form' : class does not have a copy-constructor
I tried the first line as "Form1 frm = ..." and also "frmChildTest frm = ..." with similar results.
What am I missing here
Thanks, again.
edit: thanks for the code tag tip
QUE??
Thanks for the reply.
That makes sense, but it won't seem to let me.
The object I am adding to the panel is not out of the tool box (it is a seperate graphics display with it's own keyboard input) and when I try your code I get a compile errors about :
cannot convert 'IObjDisplay*' to 'System::Windows::Forms::Controls^'
and 'Focus' is not a member of 'IObjDisplay"
I was trying where the Form is created like this:
private: System::Void::Form1_Load( etc. etc. ~)
{
ObjDisplay = new IObjDisplay(); //This line I already have here works fine
MyPanel.Controls.Add(ObjDisplay);
ObjDisplay->Focus();
}
Down where the panel is drawn, I am initialising things with:
private: System::Void MyPanel_Paint_1(etc. etc. ~)
{
ObjDisplay->initial((this->MyPanel->Handle.ToPointer()); //my display shows fine in the panel here
}
I also tried using your way in that block as well with similar results.
So I am still a little stuck.
Any thoughts
zaph
Ah I didn't realize you used Managed C++. As Christian said, use gcnew. This is the code for a child form 'SomeForm' in a parent form 'Form1':
#include "SomeForm.h"
public ref class Form1 : public System::Windows::Forms::Form
{
private: MCppForm::SomeForm^ m_ChildForm;
public:
Form1(void)
{
InitializeComponent();
m_ChildForm = gcnew MCppForm::SomeForm();
m_ChildForm->TopLevel = false;
m_ChildForm->Parent = this;
m_ChildForm->FormBorderStyle = System::Windows::Forms::FormBorderStyle::None;
m_ChildForm->Show();
}
I've also added the borderstyle code which should be set to none.
P.s.: the code tags can also take "C++" and "VB" as arguments!
nmd
What exactly is the object you are tring to set focus to
what is its base class
does a simple textbox instead works with the focus
Michael K
First, you should not be using Focus, use Select instead. Read this post on some more information.
Second, the Panel is a control that is not selectable. It has the ControlStyles.Selectable set to false. Any control derived from panel also cannot be selected. You might want to consider using a different control as a container, like a Form or a UserControl. Forms can also be used as child controls. To do so, set TopLevel to false and Parent to this.
Form frm = new SomeChildForm();
frm.TopLevel = false;
frm.Parent = this;
frm.Show();
P.s.: I saw your comment on the code tags. They work, just use 'code language="C#"' instead of just 'code'.