Click here to Skip to main content
15,913,610 members
Home / Discussions / C#
   

C#

 
GeneralRe: Only allow one call to a function at a time Pin
Dwayner795-Aug-05 11:01
Dwayner795-Aug-05 11:01 
GeneralRe: Only allow one call to a function at a time Pin
Peter Vertes5-Aug-05 11:06
Peter Vertes5-Aug-05 11:06 
GeneralRe: Only allow one call to a function at a time Pin
jan larsen8-Aug-05 22:00
jan larsen8-Aug-05 22:00 
GeneralAnimated Gif Pin
nc3b5-Aug-05 10:17
nc3b5-Aug-05 10:17 
GeneralGetting Values Out from a CheckedListBox Pin
Peter Vertes5-Aug-05 9:46
Peter Vertes5-Aug-05 9:46 
GeneralRe: Getting Values Out from a CheckedListBox Pin
Mohamad Al Husseiny5-Aug-05 22:10
Mohamad Al Husseiny5-Aug-05 22:10 
GeneralIrDA communication pocket/palm Pin
wiler5-Aug-05 9:28
wiler5-Aug-05 9:28 
GeneralInvalidating an ActiveX Browser Control to allow Painting... Pin
rcurrie5-Aug-05 7:28
rcurrie5-Aug-05 7:28 
As a continuation of this thread on transparent panels, I've come to an interesting dilema. I'm interested in having a browser window with overlaying transparent panels. The trouble I'm finding is in finding and utilizing a way to Invalidate the browser window such that it's child controls (the panels) will act 'transparent' and draw the browser contents on their background...similar to the OnPaint and OnPaintBackground events. There is sample code at the link above for a basic project example I've put together. I'll include it below just in case. You will, however, have to re-add the resouces Microsoft.mshtml & the AxSHDocVx components (probably on your toolbox with the Add Components option) If anyone has some thoughts or suggestions I would greatly appreciate it! I basically just want a way to 'draw boxes on top of' a web browser. Thanks again!

~rcurrie



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.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.Controls.Add(label3);<br />
			this.axWebBrowser1.TabIndex = 1;<br />
			this.axWebBrowser1.Invalidated += new InvalidateEventHandler(axWebBrowser1_Invalidated);<br />
			this.axWebBrowser1.Validated += new EventHandler(axWebBrowser1_Validated);<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.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 />
		private void axWebBrowser1_Validated(object sender, EventArgs e)<br />
		{<br />
		}<br />
	}<br />
}<br />

GeneralC# and VTK Pin
patgo5-Aug-05 5:39
patgo5-Aug-05 5:39 
GeneralRe: C# and VTK Pin
ganeshraju22-Jun-10 14:38
ganeshraju22-Jun-10 14:38 
GeneralRe: C# and VTK Pin
patgo22-Jun-10 23:37
patgo22-Jun-10 23:37 
GeneralRe: C# and VTK Pin
macengineer11-Jun-12 21:25
macengineer11-Jun-12 21:25 
Generalcrystal reports Pin
magnifique5-Aug-05 5:14
magnifique5-Aug-05 5:14 
GeneralImplementing password rules Pin
Adam °Wimsatt5-Aug-05 4:56
Adam °Wimsatt5-Aug-05 4:56 
GeneralRe: Implementing password rules Pin
Alomgir Miah5-Aug-05 5:22
Alomgir Miah5-Aug-05 5:22 
GeneralRe: Implementing password rules Pin
Adam °Wimsatt5-Aug-05 5:28
Adam °Wimsatt5-Aug-05 5:28 
GeneralRe: Implementing password rules Pin
Vasudevan Deepak Kumar5-Aug-05 5:23
Vasudevan Deepak Kumar5-Aug-05 5:23 
GeneralRe: Implementing password rules Pin
Adam °Wimsatt5-Aug-05 5:36
Adam °Wimsatt5-Aug-05 5:36 
GeneralRe: Implementing password rules Pin
User 66585-Aug-05 5:35
User 66585-Aug-05 5:35 
GeneralRe: Implementing password rules Pin
Adam °Wimsatt5-Aug-05 5:43
Adam °Wimsatt5-Aug-05 5:43 
GeneralRe: Implementing password rules Pin
Dan Neely5-Aug-05 7:04
Dan Neely5-Aug-05 7:04 
GeneralCreating mapper application using C# Pin
GoTech5-Aug-05 4:23
GoTech5-Aug-05 4:23 
Generalcreate View Pin
magnifique5-Aug-05 4:01
magnifique5-Aug-05 4:01 
GeneralMultiple projects in a single Solution - Sharing Classes Pin
BinaryHead5-Aug-05 3:52
BinaryHead5-Aug-05 3:52 
GeneralRe: Multiple projects in a single Solution - Sharing Classes Pin
mav.northwind5-Aug-05 4:10
mav.northwind5-Aug-05 4:10 

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.