UserControl在VisualStudio中停靠 [英] UserControl Docking in VisualStudio

查看:110
本文介绍了UserControl在VisualStudio中停靠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我在这里这是我的任务,我想知道如何停靠用户控制让我解释我想要的东西,



我设计的From1和UserControl1和这个Form1,它的panel1和toolStripButton1。按钮设置调用UserControl1它没关系,但我不知道如何设置它自动调整Form1的panel1宽度和高度。所以任何人都可以帮助我



UserControl1





Hi everyone I here this is a my assignment, I want to know how can dock an User Control let me explain what I want,

I designed From1 and UserControl1 and this the Form1, its panel1 and toolStripButton1. button set to call UserControl1 its ok, but i don't know how can I set it to automatically resize with Form1's panel1 width and height. so can anyone help me please

UserControl1


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace XyZ
{
    public partial class UserControl1 : UserControl
    {
        public UserControl1()
        {
            InitializeComponent();
        }

        private void UserControl1_Load(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }
    }
}





Form1--





Form1--

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace XyZ
{
    public partial class CustomerInvoice : Form
    {
        public CustomerInvoice()
        {
            InitializeComponent();
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            panel1.Controls.Clear();
            UserControl1 ust2 = new UserControl1();
            panel1.Controls.Add(ust2);

        }

        private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }
    }
}

推荐答案

最简单的方法是使用Dock或主播属性:

https:// msdn.microsoft.com/en-us/library/vstudio/77cb86s0(v=vs.100).aspx [ ^ ]

https://msdn.microsoft.com/en-us/library/system.windows.forms.control.anchor(V = vs.110)的.aspx [ ^ ]

Dock适合控件到边缘,Anchor将它们锁定到边缘。
The easiest way is to use the Dock or Anchor properties:
https://msdn.microsoft.com/en-us/library/vstudio/77cb86s0(v=vs.100).aspx[^]
https://msdn.microsoft.com/en-us/library/system.windows.forms.control.anchor(v=vs.110).aspx[^]
Dock "fits" controls to edges, Anchor "locks" them to edges.


这篇关于UserControl在VisualStudio中停靠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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