Jump to content

Change CSS in RunTime


mikromundo

Recommended Posts

Hi, in UniTreeMenu I have a CSS. In RunTime I want to change the background-color:

.x-treelist-nav {       /* Aqui ira determina a COR DE Fundo do menu */
    background-color: [[MENU_COLOR]] !important;    //<------ I want to change here

}

thanks for help !!!

Link to comment
Share on other sites

/* CustomCSS */
.tree_menu .x-treelist-nav {
    background-color: red;
}
// RunTime

procedure TMainForm.btnAddClick(Sender: TObject);
begin
 UniSession.AddJS('$(''#'+TUniControl(UniTreeMenu1).JSId+''').addClass(''tree_menu'')');
end;

procedure TMainForm.btnRemoveClick(Sender: TObject);
begin
 UniSession.AddJS('$(''#'+UniTreeMenu1.JSId+''').removeClass(''tree_menu'')');
end;

Best Regards

Eduardo Belo

  • Like 1
Link to comment
Share on other sites

obrigado  belo... mas consegui aqui...era isso que queria:

 

     UniSession.AddJS('$(''.x-treelist-nav .x-treelist-item-text'').css({ ''color'': ''' + ( ColorToHtml( btnSelColor_MenuFont.Color ) ) + ''' })' );

 

deu certinho !!!

Mas muito obrigado mesmo assim !!!

 

Link to comment
Share on other sites

  • 1 year later...

A way to add custom CSS to individual frames and forms:

Create a CSS file to override or add classes. If you create a new class and want to assign it to a component put the class name in LayoutConfig.Cls of the component.

1. CSS File example.css:

/*Rounded edges on edits*/
.x-textfield .x-input-wrap-el {
    -webkit-border-radius: 3px; !important;
}
/*class FormSubmitButton*/
.FormSubmitButton {
    font: 16px 'Open Sans', 'Helvetica Neue', helvetica, arial, sans-serif;
    background: #47a404;
    background-color: #47a404;
    color: #fff;
    font-weight: 600;
    border-radius: 3px;
    padding-top: 5px;
    padding-right: 5px;
    padding-bottom: 5px;
    padding-left: 5px;
}
.FormSubmitButton.x-hovered {
    color: #fff;
    background: #378003;
    background-color: #378003;    
}
.FormSubmitButton .x-inner-el {
    padding: 7px;
    border: 0px;
    background-color: #47a404;
    background-image: none;
}
.FormSubmitButton.x-hovered .x-inner-el {
    background: #378003;
    background-color: #378003;     
}

 

2. Set LayoutConfig.Cls of your button to FormSubmitButton


3. Put the following in form/frame OnCreate

procedure Ttestframe.UniFrameCreate(Sender: TObject);
Var Script:String;
begin
        Script := 'var fileref = document.createElement("link");'+#13#10+
        'fileref.rel = "stylesheet";'+#13#10+
        'fileref.type = "text/css";'+#13#10+
        'fileref.href = "/css/example.css";'+#13#10+ //<-- Path to CSS file
        'document.getElementsByTagName("head")[0].appendChild(fileref);';
        TUnimForm(Self.OwnerForm).WebForm.Script.Add(Script); //<-- In Frame
        //Self.WebForm.Script.Add(Script); //<-- In Form
end;

 

Link to comment
Share on other sites

On 12/14/2019 at 8:34 AM, belo said:

/* CustomCSS */
.tree_menu .x-treelist-nav {
    background-color: red;
}

// RunTime

procedure TMainForm.btnAddClick(Sender: TObject);
begin
 UniSession.AddJS('$(''#'+TUniControl(UniTreeMenu1).JSId+''').addClass(''tree_menu'')');
end;

procedure TMainForm.btnRemoveClick(Sender: TObject);
begin
 UniSession.AddJS('$(''#'+UniTreeMenu1.JSId+''').removeClass(''tree_menu'')');
end;

Best Regards

Eduardo Belo

for cBuilder:

void __fastcall TMainForm::UniBitBtn1Click(TObject *Sender)
{//修改背景颜色
UniSession->AddJS("$(\"#"+UniTreeMenu1->JSId+ "\").addClass('tree_menu')");
}
//---------------------------------------------------------------------------

void __fastcall TMainForm::UniBitBtn2Click(TObject *Sender)
{//恢复背景颜色
UniSession->AddJS("$(\"#"+UniTreeMenu1->JSId+ "\").removeClass('tree_menu')");
}
//---------------------------------------------------------------------------

Link to comment
Share on other sites

On 4/24/2021 at 7:18 AM, Haklin0816 said:

A way to add custom CSS to individual frames and forms:

Create a CSS file to override or add classes. If you create a new class and want to assign it to a component put the class name in LayoutConfig.Cls of the component.

1. CSS File example.css:


/*Rounded edges on edits*/
.x-textfield .x-input-wrap-el {
    -webkit-border-radius: 3px; !important;
}
/*class FormSubmitButton*/
.FormSubmitButton {
    font: 16px 'Open Sans', 'Helvetica Neue', helvetica, arial, sans-serif;
    background: #47a404;
    background-color: #47a404;
    color: #fff;
    font-weight: 600;
    border-radius: 3px;
    padding-top: 5px;
    padding-right: 5px;
    padding-bottom: 5px;
    padding-left: 5px;
}
.FormSubmitButton.x-hovered {
    color: #fff;
    background: #378003;
    background-color: #378003;    
}
.FormSubmitButton .x-inner-el {
    padding: 7px;
    border: 0px;
    background-color: #47a404;
    background-image: none;
}
.FormSubmitButton.x-hovered .x-inner-el {
    background: #378003;
    background-color: #378003;     
}

 

2. Set LayoutConfig.Cls of your button to FormSubmitButton


3. Put the following in form/frame OnCreate


procedure Ttestframe.UniFrameCreate(Sender: TObject);
Var Script:String;
begin
        Script := 'var fileref = document.createElement("link");'+#13#10+
        'fileref.rel = "stylesheet";'+#13#10+
        'fileref.type = "text/css";'+#13#10+
        'fileref.href = "/css/example.css";'+#13#10+ //<-- Path to CSS file
        'document.getElementsByTagName("head")[0].appendChild(fileref);';
        TUnimForm(Self.OwnerForm).WebForm.Script.Add(Script); //<-- In Frame
        //Self.WebForm.Script.Add(Script); //<-- In Form
end;

 

for cBuilder:

void __fastcall TMainmForm::UnimFormCreate(TObject *Sender)
{
String Script;
Script = "var fileref = document.createElement(\"link\");";
Script+="fileref.rel = \"stylesheet\";";
Script+="fileref.type = \"text/css\";";
Script+="fileref.href = \"/css/example.css\";"; //<-- Path to CSS file
Script+="document.getElementsByTagName(\"head\")[0].appendChild(fileref);";
//TUnimForm(Self.OwnerForm).WebForm.Script.Add(Script); //<-- In Frame
this->WebForm->Script->Add(Script); //<-- In Form
}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...