Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Form designer partial class.
- //CHANGE NAMESPACE NAME
- namespace EmbeddedForms
- {
- partial class frmEmbeddedForms
- {
- private System.ComponentModel.IContainer components = null;
- protected override void Dispose(bool disposing)
- {
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
- #region Windows Form Designer generated code
- private void InitializeComponent()
- {
- this.panTitleBar = new System.Windows.Forms.Panel();
- this.lblTitle = new System.Windows.Forms.Label();
- this.panContainer = new System.Windows.Forms.Panel();
- this.panSideBar = new System.Windows.Forms.Panel();
- this.btnHideSideBar = new System.Windows.Forms.Button();
- this.btnNoBorder = new System.Windows.Forms.Button();
- this.btnEmbedForm = new System.Windows.Forms.Button();
- this.panTitleBar.SuspendLayout();
- this.panSideBar.SuspendLayout();
- this.SuspendLayout();
- //
- // panTitleBar
- //
- this.panTitleBar.BackColor = System.Drawing.Color.OliveDrab;
- this.panTitleBar.Controls.Add(this.lblTitle);
- this.panTitleBar.Dock = System.Windows.Forms.DockStyle.Top;
- this.panTitleBar.Location = new System.Drawing.Point(0, 0);
- this.panTitleBar.Name = "panTitleBar";
- this.panTitleBar.Size = new System.Drawing.Size(626, 56);
- this.panTitleBar.TabIndex = 1;
- //
- // lblTitle
- //
- this.lblTitle.Font = new System.Drawing.Font("Segoe UI", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
- this.lblTitle.Location = new System.Drawing.Point(27, 9);
- this.lblTitle.Name = "lblTitle";
- this.lblTitle.Size = new System.Drawing.Size(231, 38);
- this.lblTitle.TabIndex = 0;
- this.lblTitle.Text = "Title Bar";
- //
- // panContainer
- //
- this.panContainer.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
- this.panContainer.Dock = System.Windows.Forms.DockStyle.Fill;
- this.panContainer.Location = new System.Drawing.Point(145, 56);
- this.panContainer.Name = "panContainer";
- this.panContainer.Size = new System.Drawing.Size(481, 347);
- this.panContainer.TabIndex = 2;
- this.panContainer.Resize += new System.EventHandler(this.panContainer_Resize);
- //
- // panSideBar
- //
- this.panSideBar.Controls.Add(this.btnHideSideBar);
- this.panSideBar.Controls.Add(this.btnNoBorder);
- this.panSideBar.Controls.Add(this.btnEmbedForm);
- this.panSideBar.Dock = System.Windows.Forms.DockStyle.Left;
- this.panSideBar.Location = new System.Drawing.Point(0, 56);
- this.panSideBar.Name = "panSideBar";
- this.panSideBar.Size = new System.Drawing.Size(145, 347);
- this.panSideBar.TabIndex = 3;
- //
- // btnHideSideBar
- //
- this.btnHideSideBar.FlatAppearance.BorderSize = 0;
- this.btnHideSideBar.FlatAppearance.MouseDownBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(32)))), ((int)(((byte)(32)))), ((int)(((byte)(32)))));
- this.btnHideSideBar.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
- this.btnHideSideBar.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
- this.btnHideSideBar.Font = new System.Drawing.Font("Wingdings", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(2)));
- this.btnHideSideBar.ForeColor = System.Drawing.Color.White;
- this.btnHideSideBar.Location = new System.Drawing.Point(117, 0);
- this.btnHideSideBar.Name = "btnHideSideBar";
- this.btnHideSideBar.Size = new System.Drawing.Size(29, 31);
- this.btnHideSideBar.TabIndex = 50;
- this.btnHideSideBar.Text = "ï";
- this.btnHideSideBar.UseVisualStyleBackColor = true;
- this.btnHideSideBar.Click += new System.EventHandler(this.btnHideSideBar_Click);
- this.btnHideSideBar.MouseDown += new System.Windows.Forms.MouseEventHandler(this.btnHideSideBar_MouseDown);
- this.btnHideSideBar.MouseUp += new System.Windows.Forms.MouseEventHandler(this.btnHideSideBar_MouseUp);
- //
- // btnNoBorder
- //
- this.btnNoBorder.Enabled = false;
- this.btnNoBorder.FlatAppearance.BorderSize = 0;
- this.btnNoBorder.FlatAppearance.MouseDownBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(64)))), ((int)(((byte)(0)))));
- this.btnNoBorder.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(64)))), ((int)(((byte)(0)))));
- this.btnNoBorder.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
- this.btnNoBorder.Font = new System.Drawing.Font("Segoe UI", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
- this.btnNoBorder.ForeColor = System.Drawing.Color.White;
- this.btnNoBorder.Location = new System.Drawing.Point(0, 126);
- this.btnNoBorder.Name = "btnNoBorder";
- this.btnNoBorder.Size = new System.Drawing.Size(145, 35);
- this.btnNoBorder.TabIndex = 49;
- this.btnNoBorder.Text = "No Border";
- this.btnNoBorder.UseVisualStyleBackColor = true;
- this.btnNoBorder.Click += new System.EventHandler(this.btnNoBorder_Click);
- //
- // btnEmbedForm
- //
- this.btnEmbedForm.FlatAppearance.BorderColor = System.Drawing.Color.White;
- this.btnEmbedForm.FlatAppearance.BorderSize = 0;
- this.btnEmbedForm.FlatAppearance.MouseDownBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(64)))), ((int)(((byte)(0)))));
- this.btnEmbedForm.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(64)))), ((int)(((byte)(0)))));
- this.btnEmbedForm.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
- this.btnEmbedForm.Font = new System.Drawing.Font("Segoe UI", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
- this.btnEmbedForm.ForeColor = System.Drawing.Color.White;
- this.btnEmbedForm.Location = new System.Drawing.Point(0, 70);
- this.btnEmbedForm.Name = "btnEmbedForm";
- this.btnEmbedForm.Size = new System.Drawing.Size(145, 35);
- this.btnEmbedForm.TabIndex = 48;
- this.btnEmbedForm.Text = "Embed Form";
- this.btnEmbedForm.UseVisualStyleBackColor = true;
- this.btnEmbedForm.Click += new System.EventHandler(this.btnEmbedForm_Click);
- //
- // frmEmbeddedForms
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(32)))), ((int)(((byte)(32)))), ((int)(((byte)(32)))));
- this.ClientSize = new System.Drawing.Size(626, 403);
- this.Controls.Add(this.panContainer);
- this.Controls.Add(this.panSideBar);
- this.Controls.Add(this.panTitleBar);
- this.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
- this.ForeColor = System.Drawing.Color.White;
- this.Name = "frmEmbeddedForms";
- this.ShowInTaskbar = false;
- this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
- this.Text = "frmEmbeddedForms";
- this.panTitleBar.ResumeLayout(false);
- this.panSideBar.ResumeLayout(false);
- this.ResumeLayout(false);
- }
- #endregion
- private System.Windows.Forms.Panel panTitleBar;
- private System.Windows.Forms.Label lblTitle;
- private System.Windows.Forms.Panel panContainer;
- private System.Windows.Forms.Panel panSideBar;
- private System.Windows.Forms.Button btnEmbedForm;
- private System.Windows.Forms.Button btnNoBorder;
- private System.Windows.Forms.Button btnHideSideBar;
- }
- }
- //Form code
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- //CHANGE NAMESPACE NAME
- namespace EmbeddedForms
- {
- public partial class frmEmbeddedForms : Form
- {
- System.Windows.Forms.Timer timer;
- //Define here the Form class to be embedded
- [Your Form Class] EmbeddedForm;
- public frmEmbeddedForms(Form MainForm) => InitializeComponent();
- private void btnEmbedForm_Click(object sender, EventArgs e)
- {
- EmbeddedForm = new [Your Form Class]() {
- TopLevel = false,
- Parent = panContainer,
- Location = new Point(4, 4),
- Enabled = true
- };
- EmbeddedForm.Show();
- }
- private void btnNoBorder_Click(object sender, EventArgs e)
- {
- //Position (to compensate) the embedded Form when its borders are hidden
- EmbeddedForm.Location = new Point(6, 6);
- EmbeddedForm.FormBorderStyle = FormBorderStyle.None;
- }
- private void btnHideSideBar_Click(object sender, EventArgs e)
- {
- //This timer slides the SideBar left. Another one is needed to slide right (if required)
- timer = new Timer();
- timer.Interval = 50;
- timer.Tick += (s, ev) =>
- {
- //Simply resize the SideBar
- //panSideBar.Width -= 5;
- //Or, slide the Panel's controls
- SideBar_SlideControls();
- if (panSideBar.Width <= 6)
- {
- panSideBar.Width = 6;
- timer.Stop();
- timer.Dispose(); //!important
- }
- };
- timer.Start();
- }
- private void SideBar_SlideControls()
- {
- this.panSideBar.Controls.OfType<Control>().Select(ctl => ctl.Left -= 5).ToList();
- this.panSideBar.Width -= 5;
- panSideBar.Update();
- }
- private void panContainer_Resize(object sender, EventArgs e)
- {
- //Resizes the embedded Form when the host panel resizes
- Rectangle rect = panContainer.ClientRectangle;
- rect.Inflate(-3, -3);
- EmbeddedForm.Size = rect.Size;
- }
- private void btnHideSideBar_MouseDown(object sender, MouseEventArgs e)
- {
- btnHideSideBar.FlatAppearance.BorderSize = 1;
- }
- private void btnHideSideBar_MouseUp(object sender, MouseEventArgs e)
- {
- btnHideSideBar.FlatAppearance.BorderSize = 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment