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 > สอบถามครับ การเรียกฟอร์มลูก ที่เราเปิดไว้แล้วให้แสดงออกมา



 

สอบถามครับ การเรียกฟอร์มลูก ที่เราเปิดไว้แล้วให้แสดงออกมา

 



Topic : 114678



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



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




Code (VB.NET)
    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
        Dim CurrentForm1 As Form
        For Each CurrentForm1 In Me.MdiChildren
            If TypeOf CurrentForm1 Is SaleForm Then
                CurrentForm1.MdiParent = Me
                CurrentForm1.Show()
                MessageBox.Show("ฟอร์มนี้เปิดใช้งานอยู่แล้ว  !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Question)
                Exit Sub
            End If
        Next
        Dim SaleForm1 As New SaleForm
        SaleForm.MdiParent = Me
        SaleForm.Show()

    End Sub

    Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
        Dim CurrentForm2 As Form
        For Each CurrentForm2 In Me.MdiChildren
            If TypeOf CurrentForm2 Is WithdrawForm Then
                CurrentForm2.MdiParent = Me
                CurrentForm2.Show()
                MessageBox.Show("ฟอร์มนี้เปิดใช้งานอยู่แล้ว  !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Question)
                Exit Sub
            End If
        Next
        Dim WithdrawForm1 As New WithdrawForm
        WithdrawForm.MdiParent = Me
        WithdrawForm.Show()

    End Sub

หน้าตาโปรแกรมประมาณนี้

ถ้าเรียกฟอร์มลูกมาหลายๆๆฟอร์มแล้ว ถ้าอยากเรียกฟอร์มที่เราหาไม่เจอขึ้นมาโดยการกดไปที่เมนูเดิมอีกครั้ง
จะมีmsgboxแสดงออกมาตามภาพและเมื่อกดOKไปฟอร์มนั้นจะโชว์ขึ้นมาเลย เพราะบางทีเปิดฟอร์มเยอะไปทำให้หาไม่เจอ



Tag : .NET, Ms Access, VBScript, VS 2010 (.NET 4.x), Windows







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2015-02-25 13:34:01 By : viperz4 View : 906 Reply : 1
 

 

No. 1



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



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

check ก่อนว่ามียุรึป่าวครับ
Code (VB.NET)
For Each Form As Form In Me.MdiChildren
            If Form.Text = "Form2" Then
                Exit Sub
            End If
        Next
        Dim f As New Form2()
        f.MdiParent = Me
        f.Show()


ลองทำเป็น tab control ดีไม๊ครับ
ไพไำพดกกดห

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

        }
        public cntlSidTabControl()
        {

            SetStyle(ControlStyles.DoubleBuffer, true);

            TabStop = false;

            DrawMode = TabDrawMode.OwnerDrawFixed;

            _closeButtonBrush = new SolidBrush(_closeButtonColor);

            ItemSize = new Size(ItemSize.Width, 24);

            // used to expand the tab header, find a better way

            Padding = new Point(16, 0);

        }

        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;

        [DefaultValue(16), Category("Action Buttons")]

        public int ButtonWidth
        {

            get { return _buttonWidth; }

            set { _buttonWidth = value; }

        }

        private int _crossOffset = 3;

        [DefaultValue(3), Category("Action Buttons")]

        public int CrossOffset
        {

            get { return _crossOffset; }

            set { _crossOffset = value; }

        }

        private readonly StringFormat _stringFormat = new StringFormat

        {

            Alignment = StringAlignment.Near,

            LineAlignment = StringAlignment.Center

        };

        private Color _closeButtonColor = Color.Red;

        private Brush _closeButtonBrush;

        [Category("Action Buttons")]

        public Color CloseButtonColor
        {

            get { return _closeButtonColor; }

            set
            {

                _closeButtonBrush.Dispose();

                _closeButtonColor = value;

                _closeButtonBrush = new SolidBrush(_closeButtonColor);

                Invalidate();

            }

        }

        protected override void OnDrawItem(DrawItemEventArgs e)
        {

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

                e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;

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

                    Rectangle tabArea = GetTabRect(nIndex);

                    Rectangle closeBtnRect = GetCloseBtnRect(tabArea);

                    if (nIndex != SelectedIndex)
                    {

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

                        DrawCross(e, closeBtnRect, Color.DarkGray);

                    }

                    else
                    {

                        //Drawing Close Button

                        e.Graphics.FillRectangle(_closeButtonBrush, closeBtnRect);

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

                        DrawCross(e, closeBtnRect, Color.White);

                    }

                    string str = TabPages[nIndex].Text;

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

                }

            }

        }

        private void DrawCross(DrawItemEventArgs e, Rectangle btnRect, Color color)
        {

            using (Pen pen = new 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 Rectangle GetCloseBtnRect(Rectangle tabRect)
        {

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

            return rect;

        }

        protected override void OnMouseDown(MouseEventArgs e)
        {

            if (!DesignMode)
            {

                Rectangle rect = GetTabRect(SelectedIndex);

                rect = GetCloseBtnRect(rect);

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

                if (rect.Contains(pt))
                {

                    CloseTab(SelectedTab);

                }

            }

        }

        public void CloseTab(int tabindex)
        {

            CloseTab(TabPages[tabindex]);

        }

        public void CloseTab(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 TabPage _tab;

        public ClosedEventArgs(TabPage tab)
        {

            _tab = tab;

        }

        /// <summary>

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

        /// </summary>

        public TabPage Tab
        {

            get
            {

                return _tab;

            }

        }

    }

    #endregion


เวลาใช้งานก็ประมาณ

Code (C#)
private cntlSidTabControl cntlSidTabControl1 =  new TORServices.cntlSidTabControl();
this.Controls.Add(this.cntlSidTabControl1);

cntlSidTabControl1.AddNewForm(new dbRecordData.frmALS_F_603());







แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-02-25 14:59:32 By : lamaka.tor
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : สอบถามครับ การเรียกฟอร์มลูก ที่เราเปิดไว้แล้วให้แสดงออกมา
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 อัตราราคา คลิกที่นี่