Click here to Skip to main content
15,878,748 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
hello,

I try to resize my user panel that I added Outlook

here is my code:


C#
// Copyright (c) MEMOS Software s.r.o. All rights reserved.
//
// Outlook Panel Demostration
//
// File     : PanelContainer.cs
// Author   : Lukas Neumann <[EMAIL DELETED]>
// Created  : 080622
//

using System;
using System.Drawing;
using System.Windows.Forms;
namespace OutlookPanel
{
    /// <summary>
    /// Container control which mimics Outlook panel drawing style and which holds custom nested panel
    /// </summary>
    partial class PanelContainer : UserControl
    {
        /// <summary>
        /// Default constructor
        /// </summary>
        public PanelContainer()
        {
            InitializeComponent();
        }
        /// <summary>
        /// Attach nested panel control
        /// </summary>
        /// <param name="control"></param>
        public void AttachControl(UserControl control)
        {
            this.pnlContainer.Controls.Add(control);
            control.Dock = DockStyle.Fill;
        }
        /// <summary>
        /// Custom procedure for background drawing
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPaintBackground(PaintEventArgs e)
        {
            base.OnPaintBackground(e);
            using (Pen pen = new Pen(OutlookThemes.BorderColor))
            {
                //Draw a border around the control, to provide Outlook-like design
                Rectangle rect = new Rectangle(this.pnlContainer.Left - 1, this.pnlContainer.Top - 1, this.pnlContainer.Width + 1, this.pnlContainer.Height + 1);
                e.Graphics.DrawRectangle(pen, rect);
            }
        }
        /// <summary>
        /// Size change procedure
        /// </summary>
        /// <param name="e"></param>
        protected override void OnSizeChanged(EventArgs e)
        {
            base.OnSizeChanged(e);
            //The size has been change, invalidate the control
            this.Invalidate();
        }
        /// <summary>
        /// Load event handler
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BarControlContainer_Load(object sender, EventArgs e)
        {
            //Set the background color according to the current Outlook theme
            this.BackColor = OutlookThemes.BackgroundColor;
        }
    }
}


...

I count on you to give me a hand.


[edit]
Bold converted to code block: it preserves the formatting
Email removed: never post your email to any public forum, unless you really like spam
Urgency deleted: it may be urgent to you, but it isn't to us. You will annoy people if you stress the urgency, as it makes them think you were too lazy to start your homework in time (whether that is the case or not).
OriginalGriff
[/edit]
Posted
Updated 25-Jan-11 8:19am
v2

1 solution

Okay, I am not sure that will work as you expect. You cannot use that control's Graphics object to draw outside the bounds of that control. A better and more workable solution would be to make sure that your child control leaves a small margin on all 4 sides, and then the outer control paints over this margin area.
 
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