Click here to Skip to main content
15,904,351 members
Home / Discussions / C#
   

C#

 
GeneralRe: Transparent Overlapping Panels Problem... Pin
rcurrie21-Jul-05 12:46
rcurrie21-Jul-05 12:46 
GeneralRe: Transparent Overlapping Panels Problem... Pin
[Marc]21-Jul-05 15:56
[Marc]21-Jul-05 15:56 
GeneralRe: Transparent Overlapping Panels Problem... Pin
rcurrie22-Jul-05 7:29
rcurrie22-Jul-05 7:29 
GeneralRe: Transparent Overlapping Panels Problem... Pin
[Marc]22-Jul-05 9:00
[Marc]22-Jul-05 9:00 
GeneralRe: Transparent Overlapping Panels Problem... Pin
rcurrie22-Jul-05 9:06
rcurrie22-Jul-05 9:06 
GeneralRe: Transparent Overlapping Panels Problem... Pin
[Marc]22-Jul-05 9:28
[Marc]22-Jul-05 9:28 
GeneralRe: Transparent Overlapping Panels Problem... Pin
rcurrie25-Jul-05 14:02
rcurrie25-Jul-05 14:02 
GeneralRe: Transparent Overlapping Panels Problem... Pin
[Marc]26-Jul-05 7:55
[Marc]26-Jul-05 7:55 
This works (for me), i copied it from Reflector:
namespace TransparentPanels
{
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Runtime.CompilerServices;
    using System.Windows.Forms;

    public class TransPanelForm : Form
    {
        // Methods
        public TransPanelForm()
        {
            this.FinalRects = new ArrayList();
            this.InitializeComponent();
            this.SetStyle(ControlStyles.DoubleBuffer | 
                         (ControlStyles.AllPaintingInWmPaint | 
                          ControlStyles.UserPaint), true);
        }

        private Rectangle CalcDragRect(int mouseX, int mouseY)
        {
            return Rectangle.FromLTRB(Math.Min(mouseX, this.MouseDownPos.X), 
                                      Math.Min(mouseY, this.MouseDownPos.Y), 
                                      Math.Max(mouseX, this.MouseDownPos.X), 
                                      Math.Max(mouseY, this.MouseDownPos.Y));
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        public static void DrawRect(Graphics g, Rectangle rect, Pen pen)
        {
            if ((rect.Width == 0) && (rect.Height == 0))
            {
                g.DrawLine(pen, (float)rect.X, (float)rect.Y, 
                                (float)rect.X, (float)(rect.Y + 0.01f));
            }
            else if ((rect.Width > 0) && (rect.Height == 0))
            {
                g.DrawLine(pen, rect.X, rect.Y, rect.Right, rect.Y);
            }
            else if ((rect.Width == 0) && (rect.Height > 0))
            {
                g.DrawLine(pen, rect.X, rect.Y, rect.X, rect.Bottom);
            }
            else
            {
                g.DrawRectangle(pen, rect);
            }
        }

        [DebuggerStepThrough]
        private void InitializeComponent()
        {
            this.Panel1 = new Label();
            this.Panel2 = new Label();
            this.SuspendLayout();
            this.Panel1.BackColor = Color.Transparent;
            this.Panel1.BorderStyle = BorderStyle.FixedSingle;
            this.Panel1.Dock = DockStyle.Left;
            Point point1 = new Point(10, 10);
            this.Panel1.Location = point1;
            this.Panel1.Name = "Panel1";
            Size size1 = new Size(270, 0x10a);
            this.Panel1.Size = size1;
            this.Panel1.TabIndex = 0;
            this.Panel2.BackColor = Color.Transparent;
            this.Panel2.BorderStyle = BorderStyle.FixedSingle;
            this.Panel2.Dock = DockStyle.Right;
            point1 = new Point(290, 10);
            this.Panel2.Location = point1;
            this.Panel2.Name = "Panel2";
            size1 = new Size(0x110, 0x10a);
            this.Panel2.Size = size1;
            this.Panel2.TabIndex = 0;
            size1 = new Size(5, 13);
            this.AutoScaleBaseSize = size1;
            size1 = new Size(0x23c, 0x11e);
            this.ClientSize = size1;
            this.Controls.Add(this.Panel2);
            this.Controls.Add(this.Panel1);
            this.DockPadding.All = 10;
            this.Name = "TransPanelForm";
            this.Text = "TransPanelForm";
            this.ResumeLayout(false);
        }

        [STAThread]
        public static void Main()
        {
            Application.Run(new TransPanelForm());
        }

        protected override void OnPaintBackground(PaintEventArgs e)
        {
            base.OnPaintBackground(e);
            Rectangle rectangle1 = this.ClientRectangle;
            LinearGradientBrush brush1 = new LinearGradientBrush(rectangle1, 
                                         Color.White, Color.LightSteelBlue, 
                                         LinearGradientMode.ForwardDiagonal);
            e.Graphics.FillRectangle(brush1, rectangle1);
            brush1.Dispose();
        }

        protected override void OnSizeChanged(EventArgs e)
        {
            base.OnSizeChanged(e);
            this.Invalidate();
        }

        private void Panel1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                Point point1 = new Point(e.X, e.Y);
                this.MouseDownPos = point1;
                this.LeftMouseDown = true;
                Rectangle rectangle1 = new Rectangle(e.X, e.Y, 0, 0);
                this.DragRect = rectangle1;
                this.Panel2.Invalidate();
            }
        }

        private void Panel1_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                this.DragRect = this.CalcDragRect(e.X, e.Y);
                this.Panel1.Invalidate();
            }
        }

        private void Panel1_MouseUp(object sender, MouseEventArgs e)
        {
            if (this.LeftMouseDown)
            {
                this.LeftMouseDown = false;
                this.DragRect = this.CalcDragRect(e.X, e.Y);
                this.Panel2.Invalidate();
                this.FinalRects.Add(this.DragRect);
            }
        }

        private void Panel1_Paint(object sender, PaintEventArgs e)
        {
            if (this.LeftMouseDown)
            {
                Pen pen1 = new Pen(Color.Blue);
                pen1.DashStyle = DashStyle.Dash;
                TransPanelForm.DrawRect(e.Graphics, this.DragRect, pen1);
                pen1.Dispose();
            }
        }

        private void Panel2_Paint(object sender, PaintEventArgs e)
        {
            IEnumerator enum1;
            try
            {
                enum1 = this.FinalRects.GetEnumerator();
                while (enum1.MoveNext())
                {
                    Rectangle rectangle1 = (Rectangle) enum1.Current;
                    TransPanelForm.DrawRect(e.Graphics, rectangle1, Pens.Red);
                }
            }
            finally
            {
             }
        }

        // Properties
        internal virtual Label Panel1
        {
            get
            {
                return this._Panel1;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._Panel1 != null)
                {
                    this._Panel1.Paint -= new PaintEventHandler(this.Panel1_Paint);
                    this._Panel1.MouseMove -= new MouseEventHandler(this.Panel1_MouseMove);
                    this._Panel1.MouseUp -= new MouseEventHandler(this.Panel1_MouseUp);
                    this._Panel1.MouseDown -= new MouseEventHandler(this.Panel1_MouseDown);
                }
                this._Panel1 = value;
                if (this._Panel1 != null)
                {
                    this._Panel1.Paint += new PaintEventHandler(this.Panel1_Paint);
                    this._Panel1.MouseMove += new MouseEventHandler(this.Panel1_MouseMove);
                    this._Panel1.MouseUp += new MouseEventHandler(this.Panel1_MouseUp);
                    this._Panel1.MouseDown += new MouseEventHandler(this.Panel1_MouseDown);
                }
            }
        }

        internal virtual Label Panel2
        {
            get
            {
                return this._Panel2;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._Panel2 != null)
                {
                    this._Panel2.Paint -= new PaintEventHandler(this.Panel2_Paint);
                }
                this._Panel2 = value;
                if (this._Panel2 != null)
                {
                    this._Panel2.Paint += new PaintEventHandler(this.Panel2_Paint);
                }
            }
        }

        // Fields
        [AccessedThroughProperty("Panel1")]
        private Label _Panel1;
        [AccessedThroughProperty("Panel2")]
        private Label _Panel2;
        private IContainer components;
        private Rectangle DragRect;
        private ArrayList FinalRects;
        private bool LeftMouseDown;
        private Point MouseDownPos;
    }
}










GeneralRe: Transparent Overlapping Panels Problem... Pin
rcurrie2-Aug-05 14:04
rcurrie2-Aug-05 14:04 
GeneralRe: Transparent Overlapping Panels Problem... Pin
[Marc]3-Aug-05 1:05
[Marc]3-Aug-05 1:05 
GeneralRe: Transparent Overlapping Panels Problem... Pin
rcurrie4-Aug-05 11:20
rcurrie4-Aug-05 11:20 
GeneralRe: Transparent Overlapping Panels Problem... Pin
[Marc]4-Aug-05 14:08
[Marc]4-Aug-05 14:08 
GeneralRadio_Buttons Pin
_Sirrius20-Jul-05 11:58
_Sirrius20-Jul-05 11:58 
Generalinitializing data members in a class Pin
Dragan Matic20-Jul-05 11:41
Dragan Matic20-Jul-05 11:41 
GeneralRe: initializing data members in a class Pin
Alomgir Miah20-Jul-05 12:07
Alomgir Miah20-Jul-05 12:07 
GeneralC# newbie question Pin
Tom Wright20-Jul-05 11:20
Tom Wright20-Jul-05 11:20 
GeneralRe: C# newbie question Pin
Christian Graus20-Jul-05 12:48
protectorChristian Graus20-Jul-05 12:48 
GeneralDatagrid question Pin
Tom Wright20-Jul-05 10:47
Tom Wright20-Jul-05 10:47 
GeneralRe: Datagrid question Pin
Alomgir Miah20-Jul-05 12:01
Alomgir Miah20-Jul-05 12:01 
GeneralReading custom attributes in ReflectionOnly mode Pin
Daniel Grunwald20-Jul-05 10:18
Daniel Grunwald20-Jul-05 10:18 
GeneralRe: Reading custom attributes in ReflectionOnly mode Pin
leppie20-Jul-05 10:35
leppie20-Jul-05 10:35 
GeneralRe: Reading custom attributes in ReflectionOnly mode Pin
Daniel Grunwald20-Jul-05 10:49
Daniel Grunwald20-Jul-05 10:49 
GeneralTabControl Question Pin
zaboboa20-Jul-05 9:05
zaboboa20-Jul-05 9:05 
GeneralRe: TabControl Question Pin
Alomgir Miah20-Jul-05 10:19
Alomgir Miah20-Jul-05 10:19 
Generalthree dimentional array loops problem Pin
iramg20-Jul-05 8:47
iramg20-Jul-05 8:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.