Trum
Trum

Reputation: 71

How to prevent ListView checkbox click through

I have a ListView and I have set CheckBoxes = true. The Problem is that when I click on the checkboxes the click event goes to the window behind my form i.e. click through occurs and my window is minimized. It happens only near the borders of the checkboxes, rest of the place (the empty space) it doesn't happen.

Please check snapshots here:

The listView checkboxes

image

the background image (actually an advert)

image2

you can see the colors which are appearing around checkboxes borders and the background window/image.

Any ideas what could be wrong?

EDIT:

This is the code that is run in OnLoad in parent form of this form.

protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);
    this.Opacity = 0;
    this.BackColor = Color.FromArgb(244, 244, 244);
    this.FormBorderStyle = FormBorderStyle.None;
    this.ShowInTaskbar = false;
    this.TransparencyKey = Color.FromArgb(244, 244, 244);
    oWidth = this.Width;
    btw.DoWork += new DoWorkEventHandler(btw_DoWork);
    btw.ProgressChanged += new ProgressChangedEventHandler(btw_ProgressChanged);
    btw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(btw_RunWorkerCompleted);
    btw.WorkerReportsProgress = true;
    //this.TopMost = true;
    this.TopMost = false;



}

There is a .PNG as BackgroundImage of this form (which is of Gray color.)

Upvotes: 1

Views: 108

Answers (1)

Shell
Shell

Reputation: 6849

May be the problem is in the form transparency key color of your windows form. the checkbox area backcolor and transparency key color are same. So, your checkbox is transparent. When you are click on checkbox the click goes on the background form. Use different transparency color rather then white or smoke white. for example green or blue.

EDITED:

if you can see here your background image is displaying through the front form border.

enter image description here Side By Side enter image description here

As per msdn

When the TransparencyKey property is assigned a Color, the areas of the form that have the same BackColor will be displayed transparently. Any mouse actions, such as the click of the mouse, that are performed on the transparent areas of the form will be transferred to the windows below the transparent area. For example, if the client region of a form is made transparent, clicking the mouse on that area would send the event notification of the click to any window that is below it. If the color assigned to the TransparencyKey property is the same as any controls on the form, they also will be displayed transparently. For example, if you have a Button control on a form that has its TransparencyKey property set to SystemColors.Control, the control will be displayed transparently unless the BackColor property of the Button control is changed to a different color.

Upvotes: 1

Related Questions