Click here to Skip to main content
15,922,512 members
Home / Discussions / C#
   

C#

 
GeneralRe: Repainting window. Pin
Heath Stewart8-Jul-04 16:34
protectorHeath Stewart8-Jul-04 16:34 
GeneralRe: Repainting window. Pin
Nick Z.8-Jul-04 15:43
Nick Z.8-Jul-04 15:43 
GeneralRe: Repainting window. Pin
Nick Z.8-Jul-04 16:21
Nick Z.8-Jul-04 16:21 
GeneralRe: Repainting window. Pin
Heath Stewart8-Jul-04 16:38
protectorHeath Stewart8-Jul-04 16:38 
GeneralRe: Repainting window. Pin
Nick Z.8-Jul-04 17:00
Nick Z.8-Jul-04 17:00 
GeneralRe: Repainting window. Pin
Heath Stewart8-Jul-04 17:08
protectorHeath Stewart8-Jul-04 17:08 
GeneralRe: Repainting window. Pin
Nick Z.8-Jul-04 17:51
Nick Z.8-Jul-04 17:51 
GeneralA far more superior solution. Pin
Nick Z.8-Jul-04 18:54
Nick Z.8-Jul-04 18:54 
Well this was relatively fast and easy.
Here is a MUCH better way to draw a box around the window that the mouse is moving over.

First create a new form. Magenta background. TransparencyKey magenta. TopMost true. ShowInTaskBar false. Normal window state. Any size and position. FormBorderStyle none.

Create a new onpaint event handler.

//this basically draws a nice 3d looking border INSIDE the form
private void ControlSelectorForm_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Graphics myGraphics = e.Graphics;
Pen myBlackPen = new Pen(Color.Black,1);
myBlackPen.Alignment = PenAlignment.Inset;
Pen myRedPen = new Pen(Color.Red,2);
myRedPen.Alignment = PenAlignment.Inset;
myGraphics.DrawRectangle(myBlackPen,0,0,this.Width-1,this.Height-1);
myGraphics.DrawRectangle(myRedPen,1,1,this.Width-2,this.Height-2);
myGraphics.DrawRectangle(myBlackPen,3,3,this.Width-7,this.Height-7);
}

Go to your main window mouse handler (which is linked to a system hook in my case, http://www.codeproject.com/csharp/globalhook.asp)

You should make it something like this and it does the job.

//selector is a global declaration of ControlSelectorForm and it is set to new ControlSelectorForm() on mouse click
//that starts the system wide mouse hook
private void MovingMonitor(object sender, MouseEventArgs e)
{
//get handle of mouse over window
Point mousePoint = new Point(e.X,e.Y);
//get the window
IntPtr handle = USER32.GetAncestor(USER32.WindowFromPoint(mousePoint),2);

USER32.Rect dcRect= new USER32.Rect();
USER32.Rect regionRect = new USER32.Rect();
USER32.GetWindowRect(handle,ref dcRect);
USER32.GetWindowRgnBox(handle,ref regionRect);
int width,height;

switch(USER32.GetWindowRgn(handle,GDI32.CreateRectRgn(0,0,0,0)))
{
case 0:
width = dcRect.x2 - dcRect.x1;
height = dcRect.y2 - dcRect.y1;
break;
case 2:
width = (dcRect.x2 - dcRect.x1)-(regionRect.x1+(dcRect.x2 - dcRect.x1)-regionRect.x2);
height = (dcRect.y2 - dcRect.y1)-(regionRect.y1+(dcRect.y2 - dcRect.y1)-regionRect.y2);
break;
case 3:
width = dcRect.x2 - dcRect.x1;
height = dcRect.y2 - dcRect.y1;
break;
default:
MessageBox.Show("Unexpected window style.",
"Warning!",MessageBoxButtons.OK,MessageBoxIcon.Warning);
width = dcRect.x2 - dcRect.x1;
height = dcRect.y2 - dcRect.y1;
break;
}

selector.Width = width;
selector.Height = height;
selector.Left = dcRect.x1+regionRect.x1;
selector.Top = dcRect.y1+regionRect.y1;
selector.Show();
}
General"contexMenu" in "TreeView" for specific "Node". Pin
novitzky8-Jul-04 9:50
novitzky8-Jul-04 9:50 
GeneralRe: "contexMenu" in "TreeView" for specific "Node". Pin
Judah Gabriel Himango8-Jul-04 9:59
sponsorJudah Gabriel Himango8-Jul-04 9:59 
GeneralRe: "contexMenu" in "TreeView" for specific "Node". Pin
novitzky8-Jul-04 22:01
novitzky8-Jul-04 22:01 
GeneralRe: "contexMenu" in "TreeView" for specific "Node". Pin
saud_a_k9-Jul-04 1:37
saud_a_k9-Jul-04 1:37 
GeneralReturning a String from Managed to Unmanaged Code Pin
SanShou8-Jul-04 6:25
SanShou8-Jul-04 6:25 
GeneralRe: Returning a String from Managed to Unmanaged Code Pin
Heath Stewart8-Jul-04 8:49
protectorHeath Stewart8-Jul-04 8:49 
GeneralRe: Returning a String from Managed to Unmanaged Code Pin
SanShou8-Jul-04 8:57
SanShou8-Jul-04 8:57 
Generalmicrosoft.office.interop Pin
dcronje8-Jul-04 5:49
dcronje8-Jul-04 5:49 
GeneralRe: microsoft.office.interop Pin
Heath Stewart8-Jul-04 8:28
protectorHeath Stewart8-Jul-04 8:28 
GeneralIDragSourceHelper problem Pin
TylerBrinks8-Jul-04 4:17
TylerBrinks8-Jul-04 4:17 
GeneralRe: IDragSourceHelper problem Pin
Heath Stewart8-Jul-04 5:28
protectorHeath Stewart8-Jul-04 5:28 
GeneralRe: IDragSourceHelper problem Pin
TylerBrinks8-Jul-04 5:52
TylerBrinks8-Jul-04 5:52 
GeneralRe: IDragSourceHelper problem Pin
Heath Stewart8-Jul-04 6:43
protectorHeath Stewart8-Jul-04 6:43 
GeneralRe: IDragSourceHelper problem Pin
Heath Stewart8-Jul-04 6:53
protectorHeath Stewart8-Jul-04 6:53 
GeneralForm display porblem Pin
wk_vigorous8-Jul-04 1:52
wk_vigorous8-Jul-04 1:52 
GeneralRe: Form display porblem Pin
Nick Parker8-Jul-04 3:43
protectorNick Parker8-Jul-04 3:43 
GeneralRe: Form display porblem Pin
wk_vigorous8-Jul-04 4:43
wk_vigorous8-Jul-04 4:43 

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.