Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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


C#
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--

C#
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)
        {

        }
    }
}
Posted

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900