The demo of the custom checkbox image can be seen at this page (https. Business Application Frameworks, and Reporting Systems for Visual Studio, Delphi, HTML5 or iOS & Android development. Whether using WPF, ASP.NET, WinForms, HTML5 or Windows 10, DevExpress tools help you build and deliver your best in the shortest time possible. I would like to show checkbox as toggle button. But I can't apply my custom pictures to it with CCS - still checkbox is drawn. How to accomlish this task? My CSS: inputtype=checkbox#settingsbu.
I am trying to change the default 'box image' of the checkbox with CSS, but it is not working. Is there any way around this?
TylerH5 Answers
iambriansreediambriansreedYou can use pure css, just add a label to the checkbox like this:
ali mokraniali mokraniI created a Fiddle using pure CSS. The most voted answer doesn't handle click events and won't work well, because the checkbox value won't change.
This is my example:
Basically, we need the following html:
And the following CSS:
Just check the routes of the images, and the widths and heights should be equal to the width and height of the images.On the fiddler I am using base64 encoded images.
I hope it can be useful.
TonyTonyI found another way, without using adjacent labels or surrounding divs.
My usecase was that I had a markdown parser that generates those nifty TODO lists and I wanted to style them. Changing the generated HTML wasn't a option, so I came up with this solution:
given a checkbox like this:
You can style it with visibility: hidden
on checkbox and visibility: visible
on ::after, like this:
EDIT:
@connexo in a comment pointed out that input elements cannot have content. It could be easly done using label element, for example like so (please someone correct me if this is wrong, I don't have non-webkit browser handy to test it).
The checkbox works just like normal one and you can style it anyway you like.
Maybe it'll help someody (and I can bookmark it, because I haven't found anything like this on the web)
Not the answer you're looking for? Browse other questions tagged htmlcssxhtml or ask your own question.
The TCheckBox Delphi control displays a checkbox that can be on (checked) or off (unchecked). The Checked property specifies whether the checkbox is checked or not.
When the user clicks the checkbox to change its Checked state, the OnClick event for the checkbox is fired.
Changing the Checkbox's Checked Property
Since there is no OnCheckedChanged event, you will probably handle the program logic dependent on the checked state of the checkbox in its OnClick event.
However, if you programmatically change the Checked property, the OnClick event will be fired -- even though no user interaction took place.
There are (at least) two ways to programmatically change the checked property of the checkbox while 'disabling' the OnClick event.
Remove OnClick Handler, Change Checked, Put Back the Original OnClick handler
In Delphi for Win32, an event can have only one event handler (procedure) attached to it (even though there is a way to mimic multicast events in Delphi for Win32). The OnClick event's signature of a TCheckBox control is 'type TNotifyEvent = procedure(Sender: TObject) of object;'
If you assign NIL to the OnClick event before you change the state of the checkbox, then revert to the original OnClick event handling procedure - the OnClick event will not be fired.
Checked := check;
OnClick := onClickHandler;
Usage of this procedure is simple:
The SetCheckedState above toggles the Checked property of the CheckBox1 check box.
Protected Hack: ClicksDisabled: = true
Another way to stop the OnClick from executing, when you programmatically change the Checked property of a checkbox, is to take advantage of the 'hidden' (protected) ClicksDisabled property.
By looking at the TCheckBox's SetState procedure which gets executed whenever the Checked property changes, the OnClick is fired if ClicksDisabled is not true.
Since ClicksDisabled is protected you cannot access it from your code.
Luckily, the protected hack technique enables you to access those hidden/protected properties of a Delphi control.
The accessing protected members of a component provides more info on the subject.
What you need to do is to declare a simple dummy class extending the TCheckBox in the same unit where you will use the ClicksDisabled property.
Once you get your hands on the ClicksDisabled, simply set it to true, change the Checked property, then set ClicksDisabled back to false (default value):
Note: the above code toggles the Checked property of the checkbox named 'CheckBox1' using the protected ClicksDisabled property.