mahi swetha

mahi swetha

  • NA
  • 1
  • 0

How to implement expandable and collapsable properties to an usercontrol?

Jul 2 2009 6:12 AM

My friends,
I request u to help me in sorting out a solution for a usercontrol made up of two panels.I like to implement expandable and collapsable features to usercontrol.So that the child controls or usercontrols placed below it should shift upwards and downwards along with the shift of usercontrol.
In the same usercontrol,How can i proceed if i like to resize the usercontrol at design time as well as runtime?


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

namespace
Freshm
{
[
Designer(typeof(Freshm1))]
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
private void UserControl1_Load(object sender, EventArgs e)
{
button1.Visible =
false;
button2.Visible =
true;
panel2.Visible =
true;
//if (button2.Visible == true)
//{
// this.Height = 52;
// this.Width = 150;
//}
}

#region
button_click events
private void button2_Click(object sender, EventArgs e)
{
button2.Visible =
false;
button1.Visible =
true;
panel2.Visible =
false;
if (button2.Visible == false)
{
this.Height = 52;
this.Width = 150;
panel1.Height =
this.Height;
panel1.Width =
this.Width;
}
}
private void button1_Click(object sender, EventArgs e)
{
button1.Visible =
false;
button2.Visible =
true;
panel2.Visible =
true;
if (button2.Visible == true)
{
this.Height = 146;
this.Width = 150;
panel1.Height =
this.Height;
panel1.Width =
this.Width;
}
}

#endregion


#region
Serialization
[
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public Panel ControlPanel
{
get
{
return this.panel1;
}

}
[
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public Panel ControlPanel2
{
get
{
return this.panel2;
}
}

#endregion
#region
Properties
public string DisplayText
{
get
{
return this.label1.Text;
}
set
{
label1.Text =
value;
}
}
public System.Drawing.Font TextFont
{
get
{
return this.label1.Font;
}
set
{
label1.Font =
value;
}
}
public System.Drawing.Color pnl1TextColor
{
get
{
return this.panel1.BackColor;
}
set
{
panel1.BackColor =
value;
}
}
public Color pnl2TextColor
{
get
{
return this.panel2.BackColor;
}
set
{
panel2.BackColor =
value;
}
}
public Color UCTextColor
{
get
{
return this.BackColor;
}
set
{
this.BackColor = value;
}
}
public Size UCTextsize
{
get
{
return this.Size;
}
set
{
this.Size = value;
}
}

#endregion

//private void button1_Click(Object sender,System.EventArgs e)
//{

//}
//#region Fields
//private ToggleButton btnExpandOrCollapse;
//private FrameworkElement contentElement;
//private VisualState collapsedState;
//#endregion
//public bool IsExpanded
//{
// get { return (bool)GetValue(IsExpandedProperty); }
// set
// {
// SetValue(IsExpandedProperty, value);
// if (btnExpandOrCollapse != null)
// btnExpandOrCollapse.IsChecked = IsExpanded;
// }
//}
 

}
}
 
 
 
 
 
 
 
using
System;
using
System.Collections.Generic;
using
System.Text;
using
System.Windows.Forms.Design;
namespace
Freshm
{
public class Freshm1 : ParentControlDesigner
{
public override void Initialize(System.ComponentModel.IComponent component)
{
base.Initialize(component);
if (this.Control is UserControl1)
{
this.EnableDesignMode(((UserControl1)this.Control).ControlPanel, "ControlPanel");
this.EnableDesignMode(((UserControl1)this.Control).ControlPanel2, "ControlPanel2");
}
}
}
}

 
 
 
 
 
namespace
Freshm
{
partial class UserControl1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region
Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.label1 = new System.Windows.Forms.Label();
this.button2 = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.panel2 = new System.Windows.Forms.Panel();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// panel1
//
this.panel1.BackColor = System.Drawing.SystemColors.AppWorkspace;
this.panel1.Controls.Add(this.label1);
this.panel1.Controls.Add(this.button2);
this.panel1.Controls.Add(this.button1);
this.panel1.Location = new System.Drawing.Point(0, 3);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(150, 52);
this.panel1.TabIndex = 0;
//
// label1
//
this.label1.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.label1.Font = new System.Drawing.Font("Times New Roman", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label1.ForeColor = System.Drawing.SystemColors.ControlText;
this.label1.Location = new System.Drawing.Point(31, 10);
this.label1.Margin = new System.Windows.Forms.Padding(3);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(96, 14);
this.label1.TabIndex = 2;
this.label1.Text = "Enter Ur Name";
//
// button2
//
this.button2.Image = global::Freshm.Properties.Resources.NORMALGROUPCOLLAPSE;
this.button2.Location = new System.Drawing.Point(3, 3);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(22, 23);
this.button2.TabIndex = 1;
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button1
//
this.button1.Image = global::Freshm.Properties.Resources.NORMALGROUPEXPAND;
this.button1.Location = new System.Drawing.Point(3, 3);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(22, 23);
this.button1.TabIndex = 0;
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// panel2
//
this.panel2.BackColor = System.Drawing.SystemColors.ButtonShadow;
this.panel2.Location = new System.Drawing.Point(0, 53);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(150, 94);
this.panel2.TabIndex = 1;
//
// UserControl1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.panel2);
this.Controls.Add(this.panel1);
this.Location = new System.Drawing.Point(0, -2);
this.Name = "UserControl1";
this.Size = new System.Drawing.Size(150, 145);
this.Load += new System.EventHandler(this.UserControl1_Load);
this.panel1.ResumeLayout(false);
this.ResumeLayout(false);
}

#endregion

private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Panel panel2;
}
}