Click here to Skip to main content
15,905,073 members
Home / Discussions / C#
   

C#

 
AnswerRe: Sorting in multiple columns in gridview using C# Pin
Luc Pattyn25-Oct-11 9:50
sitebuilderLuc Pattyn25-Oct-11 9:50 
GeneralRe: Sorting in multiple columns in gridview using C# Pin
Dhyanga25-Oct-11 9:53
Dhyanga25-Oct-11 9:53 
AnswerRe: Sorting in multiple columns in gridview using C# Pin
Luc Pattyn25-Oct-11 10:18
sitebuilderLuc Pattyn25-Oct-11 10:18 
QuestionDeployment of c# application with merge modules Pin
sarang_k24-Oct-11 20:49
sarang_k24-Oct-11 20:49 
AnswerRe: Deployment of c# application with merge modules Pin
Pete O'Hanlon24-Oct-11 21:05
mvePete O'Hanlon24-Oct-11 21:05 
QuestionDynamically placing Forms onto TabControl Pages - need to add threading Pin
boreland24-Oct-11 13:29
boreland24-Oct-11 13:29 
AnswerRe: Dynamically placing Forms onto TabControl Pages - need to add threading Pin
Luc Pattyn24-Oct-11 14:19
sitebuilderLuc Pattyn24-Oct-11 14:19 
GeneralRe: Dynamically placing Forms onto TabControl Pages - need to add threading Pin
boreland24-Oct-11 17:48
boreland24-Oct-11 17:48 
You might say for the challenge of it, doing what seems impossible can be fun, but really because I need this level of functionality. I have actually accomplished the task. Here's how I did it.

Main Form - Click Button to add a new Form2 to a tab control
private void button1_Click(object sender, EventArgs e)
        { 
            Form2 form2 = new Form2();   
            tabControl1.TabPages.Add("tabPage" + (tabControl1.TabPages.Count - 1).ToString()); 
            form2.TopLevel = false;
            form2.BackColor = Color.Blue; 
            tabControl1.TabPages[tabControl1.TabPages.Count - 1].Controls.Add(form2);  
            form2.Show(); 
        } 


Form2 - Has a top panel strip with a button, that when pressed opens a child form (Form3) in its own thread, within the area of second panel that sits below the top panel.

 public partial class Form2 : Form
    { 
        [DllImport("user32.dll", SetLastError = true)]
        static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

        public Form2()
        {
            InitializeComponent();
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {  
            ThreadStart ts = new ThreadStart(StartUiThread);
            Thread t = new Thread(ts);
            t.Start(); 
        }  

        public void StartUiThread()
        {
            var frm3 = new Form3();
       
            IntPtr intptr = new IntPtr(); 
            this.UIThread(delegate { intptr = this.panel2.Handle; });
            SetParent(frm3.Handle, intptr);

            Application.Run(frm3); 
        }
}

public partial class Form3 : Torbo.DockableForm
    {
        public Form3()
        {
            InitializeComponent();
        }

        private void Form3_Load(object sender, EventArgs e)
        {
            label1.Text = "Thread: " + Thread.CurrentThread.ManagedThreadId.ToString();
        }
    }

static public void UIThread(this ATE_nonATE control, Action code)
        {
            if (control.InvokeRequired)
            {
                control.BeginInvoke(code);
                return;
            }
            code.Invoke();
        } 


Two myths are busted here. You can put forms onto other controls like a tabControl and it is possible to create threaded child forms.
GeneralRe: Dynamically placing Forms onto TabControl Pages - need to add threading Pin
BobJanova24-Oct-11 23:04
BobJanova24-Oct-11 23:04 
GeneralRe: Dynamically placing Forms onto TabControl Pages - need to add threading Pin
BillWoodruff25-Oct-11 3:20
professionalBillWoodruff25-Oct-11 3:20 
GeneralRe: Dynamically placing Forms onto TabControl Pages - need to add threading Pin
boreland25-Oct-11 3:53
boreland25-Oct-11 3:53 
GeneralRe: Dynamically placing Forms onto TabControl Pages - need to add threading Pin
Pete O'Hanlon25-Oct-11 4:10
mvePete O'Hanlon25-Oct-11 4:10 
GeneralRe: Dynamically placing Forms onto TabControl Pages - need to add threading Pin
BillWoodruff25-Oct-11 14:53
professionalBillWoodruff25-Oct-11 14:53 
GeneralRe: Dynamically placing Forms onto TabControl Pages - need to add threading Pin
boreland25-Oct-11 15:49
boreland25-Oct-11 15:49 
GeneralRe: Dynamically placing Forms onto TabControl Pages - need to add threading Pin
BillWoodruff25-Oct-11 17:51
professionalBillWoodruff25-Oct-11 17:51 
GeneralRe: Dynamically placing Forms onto TabControl Pages - need to add threading Pin
boreland25-Oct-11 19:29
boreland25-Oct-11 19:29 
GeneralRe: Dynamically placing Forms onto TabControl Pages - need to add threading Pin
Pete O'Hanlon26-Oct-11 3:23
mvePete O'Hanlon26-Oct-11 3:23 
GeneralRe: Dynamically placing Forms onto TabControl Pages - need to add threading Pin
BobJanova26-Oct-11 0:35
BobJanova26-Oct-11 0:35 
GeneralRe: Dynamically placing Forms onto TabControl Pages - need to add threading Pin
BobJanova26-Oct-11 0:34
BobJanova26-Oct-11 0:34 
AnswerRe: Dynamically placing Forms onto TabControl Pages - need to add threading Pin
BillWoodruff25-Oct-11 18:01
professionalBillWoodruff25-Oct-11 18:01 
AnswerRe: Dynamically placing Forms onto TabControl Pages - need to add threading Pin
boreland7-Nov-11 13:39
boreland7-Nov-11 13:39 
Question2010 C# linq Pin
dcof24-Oct-11 12:28
dcof24-Oct-11 12:28 
AnswerRe: 2010 C# linq Pin
Not Active24-Oct-11 12:57
mentorNot Active24-Oct-11 12:57 
QuestionPoint conversion. Pin
paper6724-Oct-11 8:05
paper6724-Oct-11 8:05 
AnswerRe: Point conversion. Pin
Eddy Vluggen24-Oct-11 8:34
professionalEddy Vluggen24-Oct-11 8:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.