Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > .NET Framework > Forum > สอบถาม : การสร้างฟอร์มย่อย(mdi) บน tab control จะต้องทำยังไง



 

สอบถาม : การสร้างฟอร์มย่อย(mdi) บน tab control จะต้องทำยังไง

 



Topic : 131731



โพสกระทู้ ( 39 )
บทความ ( 0 )



สถานะออฟไลน์




อยากสร้างฟอร์มย่อย(mdi) ใน Tab Control ตามรูปนะคับ
แต่ไม่รู้ว่าจะต้องเริ่มทำจากอะไร
สิ่งที่สงสัยคือ
1.ทำให้ฟอร์มย่อย(mdi) ไปอยู่ใน Tab Control ยังไง
2.ถ้าฟอร์มย่อยนั่น เปิดอยู่แล้ว จะทำยังไงให้ไม่สามารถเปิดซ้ำได้(หรือนำฟอร์มที่เปิดอยู่แล้วมาแสดงแทนการเปิดใหม่)

mdi tabcontrol



Tag : .NET, VB.NET, VS 2010 (.NET 4.x), Windows







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2018-08-08 11:18:03 By : pattaphol View : 2815 Reply : 6
 

 

No. 4

Guest


ว่าแต่วัตถุประสงค์ของท่าน คือต้องการสร้างเองโดยไม่พึ่ง Third party หรือใช้ Third party
หากต้องสร้างเองข้อนี้ผมไม่รู้ว่าสร้างยังไง แต่ที่แน่ ๆ ตัวอย่าง GUI Form ที่คุณแนบมา ใช้
Third party ร่วมอย่างแน่นอน

ลิ้งค์ Third party มีให้เลือกมากมายแล้วแต่คุณจะเลือกเจ้าไหน
https://www.infoq.com/research/dotnet-web-components

ตัวอย่างที่ผมใช้ของ Devexpress ก็มี Control xtraTabbedMdiManager ที่สามารถปรับฟอร์มให้อยู่ในรูปแบบนี้ได้ ตามรูป
Frm


ข้างล่างนี้เป็นโค้ดที่ผมเรียกใช้เปิดฟอร์ม

Class form
Code (VB.NET)
Public NotInheritable Class ClsForm

    'เปิดฟอร์มที่ระบุ
    Public Shared Sub Show_Form(Form_Name As Form)

    	If Check_Form_Open(Form_Name.Name.ToString()) = True Then ' หากมีฟอร์มที่เปิดอยู่แล้วให้ Active

             Form_Name.MdiParent = FMain.ActiveForm
             Form_Name.Activate()
             Form_Name.WindowState = FormWindowState.Maximized
             Form_Name.StartPosition = FormStartPosition.CenterParent

        Else 'กรณีที่ยังไม่เปิดฟอร์มให้ Show

             Form_Name.MdiParent = FMain.ActiveForm
             Form_Name.Show()

        End If


    End Sub

    'ตรวจสอบฟอร์มถูกเปิดใช้งานอยู่หรือไม่ True = พบฟอร์มที่เปิดอยู่ / False ไม่พบฟอร์มที่เปิดอยู่
    Private Shared Function Check_Form_Open(Form_Name As String) As Boolean

        Dim fc As FormCollection = Application.OpenForms

        For Each frm As Form In fc

            If frm.Name = Form_Name Then
                Return True
                Exit Function
            End If

        Next

        Return False

    End Function


End Class


โค้ดเรียกใช้ Show / Active form ดังนี้

Code (VB.NET)
'ฟอร์ม1
    Private Sub stbtMenu1_Click(sender As Object, e As EventArgs) Handles stbtMenu1.Click
        ClsForm.Show_Form(Form1)
    End Sub







แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-08-08 12:53:50 By : K
 


 

No. 5



โพสกระทู้ ( 39 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 4 เขียนโดย : K เมื่อวันที่ 2018-08-08 12:53:50
รายละเอียดของการตอบ ::
วิธีการยังไงก็ได้ครับ จะสร้างเองหรือใช้ Third party ร่วมก็ได้คับ
แต่ที่ผมตั้งกระทู้คำถามนี้ คือผมไม่รู้ว่าเขาเรียกกันว่าอะไร มันเลยทำให้จับคำในการ search ต่อไม่ถูกคับ (ผมลอง search แล้ว แต่ก็ไม่ได้ในสิ่งที่ต้องการค้นหาคับ)

แล้วก็ขอบคุณมากนะคับ สำหรับคำแนะนำ กับ code

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-08-08 13:40:45 By : pattaphol
 

 

No. 6

Guest


ตอบความคิดเห็นที่ : 5 เขียนโดย : pattaphol เมื่อวันที่ 2018-08-08 13:40:45
รายละเอียดของการตอบ ::
ถ้าเป็น Third party ก็ลองดูตามลิ้งค์ที่ผมแนบในความเห็น 4 ได้เลยครับ
เสริม Third party อีกเจ้า (Syncfusion) เค้ามี Community License ให้ใช้อยู่ตามเงือนไขอยู่ครับ
https://www.syncfusion.com/products/communitylicense

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-08-08 14:19:45 By : K
 


 

No. 7



โพสกระทู้ ( 4,436 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

ตัวนี้ใช้ใน tabcontrol นะครับ
Code (C#)
public void AddNewForm(System.Windows.Forms.Form form,System.Windows.Forms.TabControl tab)
        {
            for (int i = 0; i < tab.TabCount;i++ )
            {
                if (tab.TabPages[i].Text == form.Text)
                {
                    tab.TabIndex = i;
                    return;
                }
            }
            System.Windows.Forms.TabPage tab = new  System.Windows.Forms.TabPage();
            tab.Controls.Add(tab);
            form.TopLevel = false;
            form.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right | System.Windows.Forms.AnchorStyles.Left);
            form.Dock = System.Windows.Forms.DockStyle.Fill;
            form.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            form.Parent = tab;
            tab.Text = form.Text;
            try { form.Show(); }
            catch { }
         
            tab.SelectedTab = tab;

        }


ถ้าใช้ทั้ง tab จะประมาณนี้ครับ

Code (C#)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TORServices.FormsTor
{
    #region _SidTabControl
    public class SideTabControl : System.Windows.Forms.TabControl
    {

        public void AddNewForm(System.Windows.Forms.Form form)
        {
            for (int i = 0; i < this.TabCount;i++ )
            {
                if (this.TabPages[i].Text == form.Text)
                {
                    this.TabIndex = i;
                    return;
                }
            }
            System.Windows.Forms.TabPage tab = new  System.Windows.Forms.TabPage();
            this.Controls.Add(tab);
            form.TopLevel = false;
            form.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right | System.Windows.Forms.AnchorStyles.Left);
            form.Dock = System.Windows.Forms.DockStyle.Fill;
            form.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            form.Parent = tab;
            tab.Text = form.Text;
            try { form.Show(); }
            catch { }
         
            this.SelectedTab = tab;

        }
        public SideTabControl()
        {

            SetStyle(System.Windows.Forms.ControlStyles.DoubleBuffer, true);
            TabStop = false;
            DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed;
            
            _closeButtonBrush = new System.Drawing.SolidBrush(_closeButtonColor);
            ItemSize = new System.Drawing.Size(ItemSize.Width, 24);
            Padding = new System.Drawing.Point(16, 0);
			Dock = System.Windows.Forms.DockStyle.Top;

        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                _stringFormat.Dispose();
                _closeButtonBrush.Dispose();
            }
            base.Dispose(disposing);
        }

        public delegate void TabClosedDelegate(object sender, ClosedEventArgs e);
        public delegate void TabClosingDelegate(object sender, ClosingEventArgs e);
        public event TabClosedDelegate TabClosed;
        public event TabClosingDelegate TabClosing;

        private int _buttonWidth = 16;
        [System.ComponentModel.DefaultValue(16), System.ComponentModel.Category("Action Buttons")]
        public int ButtonWidth
        { get { return _buttonWidth; } set { _buttonWidth = value; }}

        private int _crossOffset = 3;

        [System.ComponentModel.DefaultValue(3), System.ComponentModel.Category("Action Buttons")]

        public int CrossOffset
        {get { return _crossOffset; } set { _crossOffset = value; }}

        private readonly System.Drawing.StringFormat _stringFormat = new System.Drawing.StringFormat

        {

            Alignment = System.Drawing.StringAlignment.Near,

            LineAlignment = System.Drawing.StringAlignment.Center

        };

        private System.Drawing.Color _closeButtonColor = System.Drawing.Color.Red;

        private System.Drawing.Brush _closeButtonBrush;

        [System.ComponentModel.Category("Action Buttons")]

        public System.Drawing.Color CloseButtonColor
        {

            get { return _closeButtonColor; }

            set
            {

                _closeButtonBrush.Dispose();

                _closeButtonColor = value;

                _closeButtonBrush = new System.Drawing.SolidBrush(_closeButtonColor);

                Invalidate();

            }

        }

        protected override void OnDrawItem(System.Windows.Forms.DrawItemEventArgs e)
        {

            if (e.Bounds != System.Drawing.RectangleF.Empty)
            {

                e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

                for (int nIndex = 0; nIndex < TabCount; nIndex++)
                {

                    System.Drawing.Rectangle tabArea = GetTabRect(nIndex);

                    System.Drawing.Rectangle closeBtnRect = GetCloseBtnRect(tabArea);

                    if (nIndex != SelectedIndex)
                    {

                        e.Graphics.DrawRectangle(System.Drawing.Pens.DarkGray, closeBtnRect);

                        DrawCross(e, closeBtnRect, System.Drawing.Color.DarkGray);

                    }

                    else
                    {

                        //Drawing Close Button

                        e.Graphics.FillRectangle(_closeButtonBrush, closeBtnRect);

                        e.Graphics.DrawRectangle(System.Drawing.Pens.White, closeBtnRect);

                        DrawCross(e, closeBtnRect, System.Drawing.Color.White);

                    }

                    string str = TabPages[nIndex].Text;

                    e.Graphics.DrawString(str, Font, new System.Drawing.SolidBrush(TabPages[nIndex].ForeColor), tabArea, _stringFormat);

                }

            }

        }

        private void DrawCross(System.Windows.Forms.DrawItemEventArgs e, System.Drawing.Rectangle btnRect, System.Drawing.Color color)
        {

            using (System.Drawing.Pen pen = new System.Drawing.Pen(color, 2))
            {

                float x1 = btnRect.X + CrossOffset;

                float x2 = btnRect.Right - CrossOffset;

                float y1 = btnRect.Y + CrossOffset;

                float y2 = btnRect.Bottom - CrossOffset;

                e.Graphics.DrawLine(pen, x1, y1, x2, y2);

                e.Graphics.DrawLine(pen, x1, y2, x2, y1);

            }

        }

        private System.Drawing.Rectangle GetCloseBtnRect(System.Drawing.Rectangle tabRect)
        {

            System.Drawing.Rectangle rect = new System.Drawing.Rectangle(tabRect.X + tabRect.Width - ButtonWidth - 4, (tabRect.Height - ButtonWidth) / 2, ButtonWidth, ButtonWidth);

            return rect;

        }

        protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
        {

            if (!DesignMode)
            {

                System.Drawing.Rectangle rect = GetTabRect(SelectedIndex);

                rect = GetCloseBtnRect(rect);

                System.Drawing.Point pt = new System.Drawing.Point(e.X, e.Y);

                if (rect.Contains(pt))
                {

                    CloseTab(SelectedTab);

                }

            }

        }

        public void CloseTab(int tabindex) {CloseTab(TabPages[tabindex]); }

        public void CloseTab(System.Windows.Forms.TabPage tp)
        {

            ClosingEventArgs args = new ClosingEventArgs(TabPages.IndexOf(tp));

            OnTabClosing(args);

            //Remove the tab and fir the event tot he client

            if (!args.Cancel)
            {

                // close and remove the tab, dispose it too

                TabPages.Remove(tp);

                OnTabClosed(new ClosedEventArgs(tp));

                tp.Dispose();

            }

        }

        protected void OnTabClosed(ClosedEventArgs e)
        {if (TabClosed != null) {TabClosed(this, e);}

        }

        protected void OnTabClosing(ClosingEventArgs e)
        { if (TabClosing != null) TabClosing(this, e);}

    }

    //Some support classes:

    public class ClosingEventArgs
    {

        private readonly int _nTabIndex = -1;

        public ClosingEventArgs(int nTabIndex)
        {

            _nTabIndex = nTabIndex;

            Cancel = false;

        }

        public bool Cancel { get; set; }

        /// <summary>

        /// Get/Set the tab index value where the close button is clicked

        /// </summary>

        public int TabIndex
        {

            get
            {

                return _nTabIndex;

            }

        }

    }

    public class ClosedEventArgs : EventArgs
    {

        private readonly System.Windows.Forms.TabPage _tab;

        public ClosedEventArgs(System.Windows.Forms.TabPage tab) { _tab = tab;}

        /// <summary>

        /// Get/Set the tab index value where the close button is clicked

        /// </summary>

        public System.Windows.Forms.TabPage Tab { get{return _tab; }}

    }

    #endregion
}



1311
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-08-08 15:22:56 By : lamaka.tor
 


 

No. 8



โพสกระทู้ ( 39 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 6 เขียนโดย : K เมื่อวันที่ 2018-08-08 14:19:45
รายละเอียดของการตอบ ::
ขอบคุณมากคับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-08-08 16:03:29 By : pattaphol
 


 

No. 9



โพสกระทู้ ( 39 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 7 เขียนโดย : lamaka.tor เมื่อวันที่ 2018-08-08 15:22:56
รายละเอียดของการตอบ ::
ขอบคุณคับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-08-08 16:14:06 By : pattaphol
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : สอบถาม : การสร้างฟอร์มย่อย(mdi) บน tab control จะต้องทำยังไง
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 00
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่