lundi 2 novembre 2020

How to copy a file into desktop when checkbox is selected in NSIS, by default the checkbox should be selected?

I want to build a custom page in installer. In this page if the checkbox is selected a file(manual) should be placed in desktop which is in another folder called nsis. But by default the checkbox should be selected and if unchecked by user it should not place the file in desktop

; === CheckBox1 

  ${NSD_CreateCheckbox} 61.87u 30.15u 161.92u 14.77u "Place the file in desktop"
  Pop $hCtl_mydialog1_CheckBox1

  ${NSD_Check} $hCtl_mydialog1_CheckBox1

  ${NSD_OnClick} $hCtl_mydialog1_CheckBox1 placePdf 

;function to place the pdf in desktop from nsis folder

Function placePdf
    
        CreateDirectory $DESKTOP\backup
        CopyFiles "C:\Users\User\nsis\Manual.pdf" $DESKTOP\backup
    
FunctionEnd

Here the file is copying correctly. But the problem is if it is not clicked (as it is by default checked) it does not place the file. How to i implemented it?




C# winform checkbox still checked

In a button click function, I set checkbox.check = false; but when I click button again, checkbox still in checked

here is my code:

// Header全選加上CheckBox
System.Drawing.Rectangle rect = dataGridView1.GetCellDisplayRectangle(0, -1, true);
rect.X = rect.Location.X + rect.Width / 4 - 9;
rect.Y = rect.Location.Y + (rect.Height / 2 - 9);
SolidBrush solidBrush = new SolidBrush(Color.White);
System.Windows.Forms.CheckBox checkBox = new System.Windows.Forms.CheckBox();
checkBox.Name = "checkBoxHeader";
checkBox.Size = new Size(18, 18);
checkBox.Location = rect.Location;
//checkBox.AutoCheck = false;
//MessageBox.Show(checkBox.Checked.ToString());
checkBox.Checked = false;
checkBox.Invalidate();
checkBox.Update();
dataGridView1.RefreshEdit();
checkBox.CheckedChanged += new EventHandler(checkBox_CheckedChanged);
dataGridView1.Controls.Add(checkBox);

I set MessageBox to show checkbox value, but the value is "False"

How can I set checkbox is unchecked when I click botton?

Thanks a lot




dimanche 1 novembre 2020

WPF CheckBox Content Template with Grid

I was wondering if it's possible to add Grid to CheckBox Content. I bind my content to multiple sources and I need to space it out nicely. For the below, even without binding: TextBlock Text="Some Text" , text won't show up. ListView will only display CheckBox without the Content.

                    <ListView.ItemTemplate>
                        <DataTemplate>

                            <CheckBox IsChecked="{Binding CheckBoxSelected, Mode=TwoWay}"  ToggleButton.Checked="Checked_Click" >
                                <Grid>
                                    <Grid.ColumnDefinitions >
                                        <ColumnDefinition Width="*" />
                                        <ColumnDefinition Width="*"/>
                                        <ColumnDefinition Width="*"/>
                                        <ColumnDefinition Width="*"/>
                                    </Grid.ColumnDefinitions>
                                    <TextBlock Text="{Binding Building}" Grid.Column="0" Foreground="Black" Cursor="Hand"  HorizontalAlignment="Left"/>
                                    <TextBlock Text="{Binding BLDName, Converter={StaticResource NrConverter}}" Grid.Column="1"   Foreground="Black" Cursor="Hand" HorizontalAlignment="Left" />
                                    <TextBlock Text=" - " Grid.Column="2"   Foreground="Black" Cursor="Hand" HorizontalAlignment="Center"  />
                                    <TextBlock Text="{Binding Structure}" Grid.Column="3"  Foreground="Black" Cursor="Hand" HorizontalAlignment="Right"  />
                                </Grid>
                            </CheckBox>

                           
                        </DataTemplate>
                    </ListView.ItemTemplate>



Unwanted 1 second lag after click event with javascript

I have javascript code that toggles from radio button 1 to radio button 2 when the user clicks anywhere on a box. It works, but only after a lag of 1 second or so. There will be a hundred of these boxes, so this lag really kills the user experience. Any clue where does this lag come from?

Note: if I remove the loop, and I target the elements with their unique ID's instead of looping through "all elements with class x", then the lag disappears. But I need the loop, considering there will be a hundred of those boxes...

Here is the javascript:

$('.checkbox-oui-non').click(function(evt) {
    var a = document.querySelectorAll(".checkbox-oui-non");
    var b = document.querySelectorAll(".checkbox-oui-non .oui");
    var c = document.querySelectorAll(".checkbox-oui-non .non");
    
    for (i = 0; i < a.length; i++) {
        if (b[i].checked ||
        c[i].checked) {
            if (b[i].checked) {
                b[i].checked = false; 
                c[i].checked = true;
            }
            else if (c[i].checked){
                b[i].checked = true; 
                c[i].checked = false;
                }
        } else {    
            b[i].checked = true;
        }
    }
});

and the html:

<div class="checkbox-oui-non">
    <span>L'enfant est né d'une précédente union</span>
    <div class="oui-non-toggle-wrapper">
        <div class="checkbox">
            <input type="radio" id="moi_oui" name="moi" class="oui">
            <label for="moi_oui">oui</label>
        </div>
        <div class="checkbox">
            <input type="radio" name="moi" id="moi_non" class="non">
            <label for="moi_non">non</label>
        </div>
        <div class="oui-non-toggle"></div>
    </div><!-- end of oui-non-wrapper -->
</div><!-- end of checkbox-oui-non -->

Thank you so much for your help!




How do i make checkbox element toggle on/off and change CSS classes/ids in Javascript [duplicate]

So i have been struggling with this for hours upon hours. I have been stuck with this for so long that i am slowly going insane. I cant recall how many times i rewrote this in different forms.

The toggle is suppose to activate "nightmode" by simply changing the classes. I have been able to chance classes/id with a simply button but couldnt make it toggle. I havent been able to do it with a "checkbox" type either.

HTML

<input type="checkbox" id="checkbox" onclick="togglenightmode">`

Javascript

var bodyclass = document.getElementsByClassName("body");

var checkboxtoggle = document.getElementById("checkbox");
 
 function togglenightmode(){
     if (checkboxtoggle.checked === false){
         bodyclass.setAttribute("class", "body");
         console.log("Nightmode is OPEN");   
     } else 
     if (checkboxtoggle.checked === true){
         bodyclass.setAttribute("class", "body-nm");
         console.log("Nightmode is CLOSED");   
    } 
}

CSS

.body {
    background-color: #eee;
}

.body-nm {
    background-color: #FFFFFF;
}

any help would be appreciated




How can i get the checkbox value from the controller class to use it in another class? JavaFX

I have this class called controller with a checkbox. I need to get this value in a class called Habitat because a method will do something according to that checkbox. I'm letting the checkbox as public static but it still saying cannot find symbol. I've imported the class too What should i do?

public class Controller {
...
 @FXML 
    public static Checkbox checkBoxRules;
...
}

public class Habitat {
...

 private void State() 
    {
        
        if (Controller.checkBoxRules.isSelected()) {
            ...
        }
}



How to use && opertor with checkboxes in php

I am trying to fetch data from MySQL database in PHP based on checkbox selected. i am fine when a single checkbox is selected then it should fetch me some data from the database, but when two or more checkboxes are selected it is not fetching the right data but coming as if it is only one checkbox selected.

example:

checkbox1 to display firstname, checkbox2 to display lastname. when checkbox1 and checkbox2 are selected should display firstname and lastname but it is only displaying firstname.

if(isset($_POST["Export"])){

    if(isset($firstname)){

        $sql = "SELECT firstname from biodata";
        $stmt = $pdo->query($sql);
    }
    elseif(isset($lastname)){

        $sql = "SELECT lastname from biodata";
        $stmt = $pdo->query($sql);
    }
   
    if(isset($firstname && $lastname)){

        $sql = "SELECT firstname,lastname from biodata";
        $stmt = $pdo->query($sql);
    }
}