导航页面控制,c#winforms的库扩展 [英] navigation page control, library extention for c# winforms

查看:114
本文介绍了导航页面控制,c#winforms的库扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

当我创建项目时,我希望在ac#WinForms中显示单个页面,与网站相同,当我点击一个navibar项目时,其他页面将显示。我已经尝试搜索但我无法找到。

喜欢这个 [ ^ ]

http://webplantmedia.com/starter-themes/wordpresscanvas/wp-content/uploads/2014/02 /Screen-Shot-2014-02-03-at-12.10.36-PM-1024x639.png [ ^ ]

您能指出我在c#中扩展的控件或库来做到这一点,而不是MDI表单吗?

谢谢!

Hi guys!
When i create my project, i want to display a single page in a c# WinForms, same as a website, when i click on an item of navibar, other page will display. I have already tried to search but i can't find out.
Like this [^]
and http://webplantmedia.com/starter-themes/wordpresscanvas/wp-content/uploads/2014/02/Screen-Shot-2014-02-03-at-12.10.36-PM-1024x639.png[^]
Can you point me control or library extended in c# to do that, not MDI form?
Thanks!

推荐答案

这里有一个关于你想要的接口类型的快速草图:



1.使用名为'MainForm的主窗体创建一个WinForm应用程序:[ ^ ]。



a。如图所示添加三个面板;他们都没有停靠;他们设置了Anchor属性,因此如果Form重新调整大小,他们将适当调整大小。



b。在pnlMenu中添加一个Button,'btnInitialize,这将触发视图/用户控件的初始创建,如代码所示。



2.添加一个Timer组件到表格,'timer1。设置它的'间隔为50ms。



3.创建一个UserControl,'ucType1Child1,大小560,508,背景色Alice-Blue。放一个TextBox,'textBox1。



MainForm代码:
Here's a quick sketch of one way to go about the kind of interface you want:

1. Create a WinForm App with a Main Form named 'MainForm like this: [^].

a. add Three Panels as shown; none of them are Docked; they have their Anchor properties set so if the Form is re-sized they will re-size appropriately.

b. add a Button to the pnlMenu, 'btnInitialize, this will trigger the initial creation of the Views/UserControls as shown in the code.

2. add a Timer component to the Form, 'timer1. Set its 'Interval to 50ms.

3. Create a UserControl, 'ucType1Child1, size 560,508, background-color Alice-Blue. Put a TextBox on it, 'textBox1.

Code for the MainForm:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;

namespace Dec12_PageSlider
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        // keep track of the current and next views
        private ucType1Child1 currentUC;
        private ucType1Child1 nextUC;

        // keep track of link between Navigator Panel and Content Panel UserControl
        private Dictionary<Button, ucType1Child1> dctBtnToUc = new Dictionary<Button, ucType1Child1>();

        // the Button the user clicked in the Navigator Panel
        private Button clickedButton;

        private void btnInitialize_Click(object sender, EventArgs e)
        {
            // to play again: clear the current controls
            if (pnlContent.Controls.Count > 0)
            {
                pnlContent.Controls.Clear();
                dctBtnToUc.Clear();
            }

            // create #5 views for testing
            for (int i = 0; i < 5; i++)
            {
                // create the view
                ucType1Child1 uc1 = new ucType1Child1 {Anchor = AnchorStyles.None, Dock = DockStyle.None};
                
                // stick something in its TextBox to identify it for testing
                uc1.setText("View " + (i + 1));

                // add the new instance of the UserControl to the Content Panel
                pnlContent.Controls.Add(uc1);

                // position the new View/UserControl outside the Content Panel
                uc1.Left = -uc1.Width - 6;
                uc1.Top = 1;

                // create the Button for the Navigator Panel
                Button btn = new Button {BackColor = Color.GhostWhite, Text = string.Format("View {0}", (i+ 1).ToString())};
                
                // add the new instance of the Button to the Navigator Panel
                pnlNavigator.Controls.Add(btn);
                
                // position the Button
                btn.Left = 50;
                btn.Top = (i*65) + 26;

                // assign the Button's ClickHandler
                btn.Click += viewBtn_Click;

                // add the new entries to the Dictionary
                dctBtnToUc.Add(btn, uc1);

                // get started: slide-in the first UserControl
                dctBtnToUc.Keys.First().PerformClick();
            }
        }

        // note this Click EventHandler is assigned to every
        // View/UserControl created
        private void viewBtn_Click(object sender, EventArgs e)
        {
            // look up the associated View/UserControl
            nextUC = dctBtnToUc[sender as Button];

            // quit here if the view did not change
            if (currentUC == nextUC) return;

            // if you uncomment this, then the pnlContent background
            // will show for a moment before the animation begins
            //if (currentUC != null) currentUC.Left = -currentUC.Width - 6;

            // make sure the next View starts outside of the Content Panel
            // probably not needed ?
            if (nextUC.Left > 0) nextUC.Left = -nextUC.Width - 6;
            
            // bring it in front
            nextUC.BringToFront();
            
            // long live the new View !
            currentUC = nextUC;

            // start the animation
            timer1.Start();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            currentUC.Left += 50;

            if (currentUC.Left >= 3)
            {
                timer1.Stop();
                currentUC.Left = 3;
            }
        }
    }
}

UserControl,'ucChild1Type1非常简单:

The UserControl, 'ucChild1Type1 is very simple:

using System.Windows.Forms;

namespace Dec12_PageSlider
{
    public partial class ucType1Child1 : UserControl
    {
        public ucType1Child1()
        {
            InitializeComponent();
        }

        public void setText(string text)
        {
            textBox1.Text = text;
        }
    }
}

这是在点击'button1并创建五个视图后运行的样子:这里我刚刚点击了'查看5按钮,该视图已在内容面板中滚动到视图中:[ ^ ]。



评论:



1.当然,还有这里需要解决的很多事情不仅仅是一个显示概念验证的原型。



2.所有那些硬编码的偏移量需要将定位转换为计算的偏移量。



3.重新调整窗体大小时重新调整视图/用户控件的大小问题在此处未解决,虽然这在技术上并不困难。



记住这个例子主要是出于教育目的,人们想要的生产代码标准不是甚至在这里尝试过。

Here's what it looks like running after 'button1 has been clicked and the five views are created: here I've just clicked on the 'View 5" Button and that view has scrolled into view in the Content Panel: [^].

Comments:

1. Of course, there are a lot of things here that would need to be worked out to go beyond just a prototype showing proof-of-concept.

2. all those hard-coded offsets for positioning would need to be transformed into calculated offsets.

3. the issue of re-sizing the view/usercontrol when the Form is re-sized is not addressed here, although that's not technically difficult.

Remember this is example is primarily meant be for educational purposes, the standards one would want for "production code" are not even attempted here.


这篇关于导航页面控制,c#winforms的库扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆