Click here to Skip to main content
15,907,329 members
Home / Discussions / C#
   

C#

 
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 
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 
Thanks [Marc],

That does indeed make sense. The ActiveX browser component that I am using does indeed have a controls property, however it doesn't function the way I would hope. So basically I have 2 labels and the browser. I have added the inner most label to the controls of the second label. I have then added this second label to the controls of the browser, and then added the browser itself to the controls of the form. That seems to be just what we're looking for here.

However, it still does not appear transparent. I think it has to do with the OnPaint event of the browser...namely that it doesnt have one. The Invalidated() event is probably quite similar, but I'm confussed on what to put in this event_handler in order to repaint the browser onto the labels?

Here is some code that demonstrates what I'm trying to do...just like above but I've added the browser to it. You'll probably have to add the AxSHDocVx resource as well as the Microsoft.mshtml resource to the project should you using it in VS.NET

using System;<br />
using System.Drawing;<br />
using System.Collections;<br />
using System.ComponentModel;<br />
using System.Windows.Forms;<br />
using System.Data;<br />
using mshtml;<br />
<br />
namespace WindowsApplication3<br />
{<br />
	public class Form1 : System.Windows.Forms.Form<br />
	{<br />
		private System.Windows.Forms.Label label3;<br />
		private System.Windows.Forms.Label label1;<br />
<br />
		private bool LeftMouseDown = false;<br />
		private Point MouseDownPos;<br />
		private Rectangle DragRect;<br />
		private ArrayList FinalRects;<br />
		private AxSHDocVw.AxWebBrowser axWebBrowser1;<br />
<br />
		private System.ComponentModel.Container components = null;<br />
<br />
		public Form1()<br />
		{<br />
			InitializeComponent();<br />
<br />
			this.axWebBrowser1.Navigate("http://www.msnbc.com");<br />
<br />
			this.MouseDownPos = new Point( 0,0 );<br />
			this.FinalRects = new ArrayList();<br />
<br />
			this.SetStyle(System.Windows.Forms.ControlStyles.SupportsTransparentBackColor, true);<br />
			this.SetStyle(System.Windows.Forms.ControlStyles.AllPaintingInWmPaint, true);<br />
			this.SetStyle(System.Windows.Forms.ControlStyles.DoubleBuffer, true);<br />
			this.SetStyle(System.Windows.Forms.ControlStyles.UserPaint, true);<br />
		}<br />
<br />
		protected override void Dispose( bool disposing )<br />
		{<br />
			if( disposing )<br />
			{<br />
				if (components != null) <br />
				{<br />
					components.Dispose();<br />
				}<br />
			}<br />
			base.Dispose( disposing );<br />
		}<br />
<br />
		#region Windows Form Designer generated code<br />
		/// <summary><br />
		/// Required method for Designer support - do not modify<br />
		/// the contents of this method with the code editor.<br />
		/// </summary><br />
		private void InitializeComponent()<br />
		{<br />
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));<br />
			this.label3 = new System.Windows.Forms.Label();<br />
			this.label1 = new System.Windows.Forms.Label();<br />
			this.axWebBrowser1 = new AxSHDocVw.AxWebBrowser();<br />
			((System.ComponentModel.ISupportInitialize)(this.axWebBrowser1)).BeginInit();<br />
			this.SuspendLayout();<br />
			// <br />
			// label1<br />
			// <br />
			this.label1.BackColor = System.Drawing.Color.Transparent;<br />
			this.label1.Dock = System.Windows.Forms.DockStyle.Fill;<br />
			this.label1.Location = new System.Drawing.Point(0, 0);<br />
			this.label1.Name = "label1";<br />
			this.label1.Size = new System.Drawing.Size(400, 400);<br />
			this.label1.TabIndex = 1;<br />
			this.label1.Paint += new System.Windows.Forms.PaintEventHandler(this.label1_Paint);<br />
			this.label1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.label1_MouseUp);<br />
			this.label1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.label1_MouseMove);<br />
			this.label1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.label1_MouseDown);<br />
			// <br />
			// label3<br />
			// <br />
			this.label3.BackColor = System.Drawing.Color.Transparent;<br />
			this.label3.Controls.Add(this.label1);<br />
			this.label3.Location = new System.Drawing.Point(188, 32);<br />
			this.label3.Name = "label3";<br />
			this.label3.Size = new System.Drawing.Size(400, 400);<br />
			this.label3.TabIndex = 0;<br />
			this.label3.Paint += new System.Windows.Forms.PaintEventHandler(this.label3_Paint);			<br />
			// <br />
			// axWebBrowser1<br />
			// <br />
			this.axWebBrowser1.Controls.Add(label3);<br />
			this.axWebBrowser1.Dock = System.Windows.Forms.DockStyle.Fill;<br />
			this.axWebBrowser1.Enabled = true;<br />
			this.axWebBrowser1.Location = new System.Drawing.Point(0, 0);<br />
			this.axWebBrowser1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axWebBrowser1.OcxState")));<br />
			this.axWebBrowser1.Size = new System.Drawing.Size(819, 476);<br />
			this.axWebBrowser1.TabIndex = 1;<br />
			this.axWebBrowser1.Invalidated += new InvalidateEventHandler(axWebBrowser1_Invalidated);<br />
			// <br />
			// Form1<br />
			// <br />
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);<br />
			this.BackColor = System.Drawing.SystemColors.Control;<br />
			this.ClientSize = new System.Drawing.Size(819, 476);<br />
			//this.Controls.Add(this.label3);<br />
			this.Controls.Add(this.axWebBrowser1);<br />
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;<br />
			this.MaximumSize = new System.Drawing.Size(825, 500);<br />
			this.MinimumSize = new System.Drawing.Size(825, 500);<br />
			this.Name = "Form1";<br />
			this.Text = "Form1";<br />
			((System.ComponentModel.ISupportInitialize)(this.axWebBrowser1)).EndInit();<br />
			this.ResumeLayout(false);<br />
<br />
		}<br />
		#endregion<br />
<br />
		[STAThread]<br />
		static void Main() <br />
		{<br />
			Application.Run(new Form1());<br />
		}<br />
<br />
		protected override void OnPaintBackground(PaintEventArgs pevent)<br />
		{<br />
			base.OnPaintBackground (pevent);<br />
		}<br />
<br />
		private void label1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)<br />
		{<br />
			if( e.Button == MouseButtons.Left )<br />
			{<br />
				Console.WriteLine("Panel2_MouseDown");<br />
				MouseDownPos = new Point(e.X, e.Y);          <br />
				LeftMouseDown = true;<br />
				DragRect = new Rectangle(e.X, e.Y, 0, 0);<br />
				this.label1.Invalidate();<br />
			}		<br />
		}<br />
<br />
		private void label1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)<br />
		{<br />
			if( e.Button == MouseButtons.Left )<br />
			{<br />
				Console.WriteLine("Panel2_MouseMove");<br />
				DragRect = CalcDragRect(e.X, e.Y);<br />
				this.label1.Invalidate();<br />
			}		<br />
		}<br />
<br />
		private void label1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)<br />
		{<br />
			if( LeftMouseDown )<br />
			{<br />
				 Console.WriteLine("Panel2_MouseUp");<br />
				LeftMouseDown = false;<br />
				DragRect = CalcDragRect(e.X, e.Y);			<br />
				this.label1.Invalidate();<br />
				FinalRects.Add(DragRect);<br />
			}<br />
		}<br />
<br />
		private void label1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)<br />
		{<br />
			if( LeftMouseDown )<br />
			{<br />
				Pen pen = new Pen(Color.Blue);<br />
				pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;<br />
				DrawRect(e.Graphics, DragRect, pen);<br />
				pen.Dispose();<br />
			}		<br />
		}<br />
<br />
		private void label3_Paint(object sender, System.Windows.Forms.PaintEventArgs e)<br />
		{<br />
			foreach( Rectangle rect in FinalRects )<br />
			{<br />
				DrawRect(e.Graphics, rect, Pens.Red);<br />
			}<br />
		}<br />
<br />
		public void DrawRect(Graphics g, Rectangle rect, Pen pen)<br />
		{<br />
			if (rect.Width == 0 && rect.Height == 0) <br />
			{<br />
				g.DrawLine(pen, rect.X, rect.Y, rect.X, rect.Y + (float)0.01);<br />
			}<br />
			else if (rect.Width > 0 && rect.Height == 0) <br />
			{<br />
				g.DrawLine(pen, rect.X, rect.Y, rect.Right, rect.Y);<br />
			}<br />
			else if (rect.Width == 0 && rect.Height > 0) <br />
			{<br />
				g.DrawLine(pen, rect.X, rect.Y, rect.X, rect.Bottom);<br />
			}<br />
			else<br />
			{<br />
				g.DrawRectangle(pen, rect);<br />
			}<br />
		}<br />
<br />
		private System.Drawing.Rectangle CalcDragRect(int mouseX, int mouseY)<br />
		{<br />
			return Rectangle.FromLTRB( System.Math.Min(mouseX, MouseDownPos.X),<br />
										System.Math.Min(mouseY, MouseDownPos.Y),<br />
										System.Math.Max(mouseX, MouseDownPos.X),<br />
										System.Math.Max(mouseY, MouseDownPos.Y) <br />
									);<br />
		}<br />
<br />
		private void axWebBrowser1_Invalidated(object sender, InvalidateEventArgs e)<br />
		{<br />
<br />
		}<br />
	}<br />
}<br />

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 
GeneralRe: three dimentional array loops problem Pin
YawgmothIII20-Jul-05 10:03
YawgmothIII20-Jul-05 10:03 
Generalgetting an enviorment variable Pin
Bic2k20-Jul-05 8:44
Bic2k20-Jul-05 8:44 
GeneralRe: getting an enviorment variable Pin
Bic2k20-Jul-05 8:57
Bic2k20-Jul-05 8:57 

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.