Click here to Skip to main content
15,867,985 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,
I created a user_control(window_form_control_library).
the problem is when I draw it on parent form it cannot be smaller.
My User_controls code is :-
using System;
using System.Drawing;
using System.Windows.Forms;

namespace WindowsFormsControlLibrary1
{
    public partial class UserControl1 : UserControl
    {
        int pos=1;
        Color clr=Color.AliceBlue;
        public UserControl1()
        {
            InitializeComponent();            
        }

        private void UserControl1_Load(object sender, EventArgs e)
        {            
            label2.Left = 0;
            label1.Left = 0;
            label2.Size = this.ClientSize;
            label1.Size = label2.Size;
            this.label1.Width = pos;
        }
        public int Value {
            get { return pos; }
            set { pos = value; changeSlide(); }
            
        }

        public Color SetColor {
            get { return clr; }
            set { clr = value; color(); }
        }
        private void changeSlide()
        {
            if (pos > 0 && pos<101)
            {
                int temp =(int) this.ClientSize.Width * pos / 100;
                label1.Width = temp;
                label1.Text = this.ClientSize.Width.ToString();
            }
        }
        private void color()
        {
            label1.BackColor = clr;
        }    
      
    }
}

I set user_control, Label1 and Label2 autoSize property to true...

Thanks in advanced..

Regards
Jayanta..
Posted
Comments
Johnny J. 15-Jul-13 14:56pm    
It cannot be smaller than what? I don't get the problem! I tried creating a usercontrol using your instructions, and I experience no difficulties in resizing it.
JayantaChatterjee 17-Jul-13 0:30am    
I mean it cannot smaller than Initial size(first time drawing size)....
Johnny J. 17-Jul-13 0:45am    
Works fine for me. Sure you haven't set the minimum size properties.
JayantaChatterjee 17-Jul-13 1:02am    
no..
Johnny J. 17-Jul-13 1:12am    
check here: http://msdn.microsoft.com/en-us/library/system.windows.forms.usercontrol.autosizemode.aspx

will not shrink below the value specified by the Size property.

What happens if you dock or anchor the usercontrol on your form?

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

  Print Answers RSS


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