informat

Hi :
I had a Form and I put the property Transparency Key to "Control" so some of the form will be hidden ....
but I still want to handle User Mouse Clicks on the hidden part of the form ... How Can I

thanks ...


Re: Windows Forms General How Can I handle Mouse events over a Form with Trancperancy Key ?

informat

up ...




Re: Windows Forms General How Can I handle Mouse events over a Form with Trancperancy Key ?

nobugz

You can't, Windows sends the mouse click to the underlying window. This is a feature, not a bug.





Re: Windows Forms General How Can I handle Mouse events over a Form with Trancperancy Key ?

informat

so : system hook is the only solution




Re: Windows Forms General How Can I handle Mouse events over a Form with Trancperancy Key ?

nobugz

Not really. The SetWindowsHookEx() callback doesn't tell you what window is being considered. You'll have a hard time figuring out the Z-order of the windows that are candidates for the mouse event.





Re: Windows Forms General How Can I handle Mouse events over a Form with Trancperancy Key ?

informat

I do n't care about what window the click happen on ...

so can you explain how I use the callback SetWindowHook() ...

thanks ...





Re: Windows Forms General How Can I handle Mouse events over a Form with Trancperancy Key ?

nobugz

Nah, I'm not interested. Google for SetWindowsHookEx and WH_MOUSE_LL. Please post back when you made it work.





Re: Windows Forms General How Can I handle Mouse events over a Form with Trancperancy Key ?

informat

I found it and used it but there is a big problem ..

I captured the mouse movements but not mouse left button clicks !!!!

my application goal is drawing on screen like rectangles , arrows ...etc ..

I used the transpranecy key to draw on form not directly to the screen ...

I want to know if user clicks the left button and drag , so I will start drawing ... if it released the left button ,I will stoped .....

thanks for your time





Re: Windows Forms General How Can I handle Mouse events over a Form with Trancperancy Key ?

nobugz

Try this:

public partial class Form1 : Form {
private Bitmap mBmp;
private Point mLastPos;
public Form1() {
InitializeComponent();
// Setup form to fill the screen
this.SetStyle(ControlStyles.Opaque, true);
this.FormBorderStyle = FormBorderStyle.None;
this.StartPosition = FormStartPosition.Manual;
this.Size = Screen.PrimaryScreen.Bounds.Size;
// Event handlers
this.Paint += Form1_Paint;
this.MouseMove += Form1_MouseMove;
this.KeyDown += Form1_KeyDown;
this.MouseDown += Form1_MouseDown;
// Make screen shot
mBmp = new Bitmap(this.Size.Width, this.Size.Height);
using (Graphics gr = Graphics.FromImage(mBmp)) {
gr.CopyFromScreen(0, 0, 0, 0, this.Size);
}
}
private void Form1_Paint(object sender, PaintEventArgs e) {
// Draw screen shot
e.Graphics.DrawImage(mBmp, 0, 0);
}
private void Form1_MouseDown(object sender, MouseEventArgs e) {
mLastPos = e.Location;
}
private void Form1_MouseMove(object sender, MouseEventArgs e) {
// Draw on bitmap when left mouse button down
if (e.Button == MouseButtons.Left) {
using (Graphics gr = Graphics.FromImage(mBmp))
gr.DrawLine(Pens.Black, mLastPos, e.Location);
mLastPos = e.Location;
this.Invalidate();
}
}
private void Form1_KeyDown(object sender, KeyEventArgs e) {
// Close form when ESC key pressed
if (e.KeyData == Keys.Escape) this.Close();
}
}






Re: Windows Forms General How Can I handle Mouse events over a Form with Trancperancy Key ?

informat

thanks again , but it is n't the solution ...

I want the form to be Transparency (that is my problem , I know how to draw and no problem ) so the user can act with other windows and in the same time drawing on screen ...

my application is an E-learing Application ...

any another solution





Re: Windows Forms General How Can I handle Mouse events over a Form with Trancperancy Key ?

informat

UP