Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Click on Label triggers BindEvent method of a CheckBox

Status
Not open for further replies.

Rajesh Karunakaran

Programmer
Sep 29, 2016
545
MU
Hi Friends,

In a form, I have created a few checkbox controls at runtime. I used BINDEVENT to map the checkbox's Click event to a method in the form itself. Below is the code generating the checkboxes (just a sample of what I am doing)

Code:
FOR c = 1 TO 6
	loName = 'chk_' + ALLTRIM(STR(c))
	thisform.AddObject(loName, 'CheckBox')
	lo = EVALUATE('thisform.' + loName)
	WITH lo
		.left        = 5
		.top         = c*15
		.BackStyle = 0
		.Caption   = ''
		.Visible   = .T.
		.Value     = .F.
	ENDWITH 
	=BINDEVENT(lo, 'Click', thisform, 'object_event_handler', 1) 
ENDFOR

Along with these, I have some labels in the form created at design time.

Now, when I click on the label, it appears that the event of the checkBox is fired and the 'object_event_handler' method is being called.

Any clue?

Rajesh
 
Rajesh,

I can't reproduce this. I have created a form with your code in the Init and with a label added at design time. But it all runs as expected. I also tried moving the code to the Click of a button.

Can you post some code to recreate the entire form?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike,

Let me try to create a form itself with the same codes that I am using in my original. If I get problem in the sample, I will post it here soon. Otherwise, obviously, my original form has something wrong that I didn't see yet. I will have to check it then.

Thanks
Rajesh
 
Mike,

I think I got the problem. It's very interesting!

In your form, place the labels very near to the right of the dynamically created checkboxes, say, about half a centimeter distance. Then, please check if you see this behavior. Or, even clicking very near to the check box also must give you that behavior. The reason is cool! However, just for a fun, can you check this please... ?

If your controls' defaults are different than mine, you may not see this. But, I want to know what you see.

Rajesh
 
Rajesh,

Yes, I can see it now. I placed the label just to the right of one of the checkboxes, and I saw the behaviour you described.

The reason is obvious. The clickable area of the checkbox is not just the checkbox itself; it is also the area occupied by the checkbox's caption. That's true, even if the caption is blank. So when you think you are clicking on the label, you might in fact be clicking on the checkbox's caption, and that would cause the event to fire.

In fact, you will see this behaviour even without the label. Run any form containing a checkbox, where the checkbox has no caption. Click about half a centimetre to the right of the checkbox. You will see the checkbox being toggled.

In your case, an easy solution would be set the checkbox's Width property to a fairly low value, perhaps 10 or 20: wide enough to make the checkbox itself visible but narrow enough to remove the caption. Experiment to get the best value.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike,

Yeah! Yeah! That was it. I had seen what it was and already solved.
:)

So, in the code, just before making the .Caption = '', I added .AutoSize = .T. and now the problem seems to be solved.

Rajesh
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top