Starting with this BHO article in C#. Tried setting the styles but it doesn't set (I don't see any change in the HTML or noticeable changes).
Tried in the OnBeforeNavigate and in the OnDocumentComplete. Is there another place I should be making these type of changes?
foreach (IHTMLElementtempElement tempElement in document.getElementsByTagName("INPUT"))
{
IHTMLInputElementinput input=(IHTMLInputElement) tempElement;
if(input.type.ToLower().Contains("password"))
{
System.Windows.Forms.MessageBox.Show("OnBeforeNavigate:"+input.value);
tempElement.setAttribute("style", "(some styles here);",0);
}
}
The IHTMLElement interface has a style property, which gives you an IHTMLStyle interface, which in turn has many properties, like color or font.
Related
I tried to make a USS variable as following:
.ds-node__text
{
background-color:#FF0000;
align-content:stretch;
}
and apply it to a label by
Laabel label = new Label()
{
text = Name
};
titleContainer.AddToClassList("ds-node__text");
titleContainer.Insert(0, label);
But the style did not applied to it.
When I change .ds-node__text. to Label, it works fine but applied to "all labels".
I went on Google and see if USS variables are applied differently, I see in the official document that it uses background instead.
But when I try it, the console told me Unknown property 'background' (did you mean 'background-color'?).
If I add > .unity-label after the variable name, it will work but add an extra empty label after the assigned label, which I don't know how to get rid of:
Why!? Where did I do wrong?
Thank you very much for your help.
I had tried:
background from USS Custom Properties
-unity-background-image-tint-color from USS Property Reference
What I'm expecting to resolve:
Successfully apply style with the variable.
I have 2 asp:RadioButton that are unchecked when the page is loaded. When one is checked, I want to change the font-weight to bold in client script. I tried:
radio1.style.fontWeight = 'bold';
but it didn't work.
You can access the the css class using the attributes property. I am assuming radio1 is the id if so you could modify your c# code to
radio1.Attributes["class"] = "newCssClassName";
I personally have never modified a single property of css using c#. To do that I have always used something like jQuery.
Try to create a new css class such as
.rbSelected
{
font-weight:bold;
{
And then toggle them accordingly ( your css property should be font-weight not fontWeight)
Also a word of warning with controls such as radio buttons and checkboxes the browser will override your styling in most cases. Each browser will render the control differently regardless of what style(s) you apply. If you are looking for something custom you may need to create your own control/element (Such as an image/element that looks like a checkbox but has manages states handled in code)
For bold
$("#YourElementID").css("font-weight","bolder");
For regular
$("#YourElementID").css("font-weight","normal");
You can create a function with this lines to toggle the font-weight. To call the javascript function from the server side controls use:
radio.Attributes.Add("onclick","functionname()");
This will add the functionname to the onclick event when the radio button is rendered to the browser.
I am making a pascal code editor in Mono in MonoDevelop. I am using Mono.TextEditor as a code editor widget. However, I cannot find how to highlight a line in the widget.
After compilation, I collect line numbers where errors occur, and so I want to highlight them in red. I found
Mono.TextEditor.LineBackgroundMarker
which seems to relate to what I want to do, but I cannot find where and how to use it.
Another option I was looking into was ViBuilder, but I don't even know how to use that. I can think of two ways to solve this problem:
Simply make highlight
Mark a line as error, as default style includes:
{ "name": "Underline(Error)", "color":"invalid-red" }
which also seems to be a possible solution.
You can highlight lines in the text editor by adding markers to the underlying document. Use the TextDocument.AddMarker method, as follows:
TextEditor textEditor;
var marker = new Mono.TextEditor.LineBackgroundMarker();
int lineNumber = ...;
textEditor.Document.AddMarker(lineNumber, marker);
textEditor.QueueDraw();
Also have a look at the Mono.TextEditor.StyleTextMarker class. This class has already the properties "BackgroundColor" / "Color" that you are looking for. Underlining may have to be done manually (for example by inheriting from StyleTextMarker and overriding the Draw method).
The code's simple enough:
page.aspx
<body id ="PageBody" runat ="server">
page.aspx.cs
if ($foo == "foo")
{
PageBody.Style.Add("background-color", "green");
}
I'd like to ignore the background color entirely when the page is printed (the PCs printing will have background turned on in their print settings for various reasons and it cannot be disabled)
I haven't worked too much with CSS from within C#, so maybe there's a way to set the body to use a specific CSS object ID conditionally? If that's the case, I can just set the BG color in the style.css and leave it out in the print.css.
Any help is greatly appreciated.
EDIT:
Took a bit more searching but adding the attribute "class" seems to do the trick.
I just call my green background when the criteria is met and call the standard style when not. Both have no background color in the print style sheet.
Adding the background color on the body element as a style attribute inline (the way you're doing) overrides the print stylesheet due to specificity. (Further worthwhile reading on CSS specificity is here.)
To get around this, you can either:
Not set the background color as an inline style (perhaps by adding a CSS class to the body element instead and styling that from CSS), or
Add !important after the background style defined in the print stylesheet, i.e. in print.css do:
body {
background-color: transparent !important;
}
How can I iterate over HTML nodes of a web page and get the CSS Text of each node in it? I need something like what Firebug is doing, if you click on a Node, it gives you complete list of all CSS Texts associated with that Node (even inherited styles).
My main problem is not actually iterating over HTML nodes. I am doing it with Html Agility Pack library. I just need to get complete CSS for each node.
p.s. I am sorry, I should have explained that I want to do this in C# (not javascript)
I found the following code snippet useful for all element in the page and 'CurrentStyle' property of them shows their computed style:
HTMLDocument doc = (HTMLDocument)axWebBrowser1.Document;
var body = (HTMLBody)doc.body;//current style
var childs = (IHTMLDOMChildrenCollection)body.childNodes;
var currentelementType = (HTMLBody)childs.item(0);
var width = currentelementType.currentStyle.width;
Note that according to my prev post axWebBrowser1 is a WebBrowser control.
If you want the current styles for an element, look into getComputedStyle(), but if you want the inheritance too then you may have to implement the style cascade. Firebug does quite a lot of work behind the scenes to generate what you see!
You can get the CSS text from the style attribute like this:
node.getAttribute('style')
Or if you want style you can iterate through the keys and values in
node.style
If you want to grab the entire computed style of the element and not just the CSS applied in the style attribute, read this article on computed and cascaded styles.
You can use WebBrowser control in C# to access the htm document object and cast its body tag as following:
HTMLDocument doc = (HTMLDocument)axWebBrowser1.Document;
var body = (HTMLBody)doc.body;
But before that you should add com refrence: MSHTML to you project.
here you could access body.currentStyle that show you all its styles that might be css or inline styles.
You can try for (property in objName) operator as seen here.
I'm not sure if you can simply get "all" CSS properties using JavaScript to be honest, you could look into the [DOMNode].currentStyle, [DOMNode].style and document.defaultView.getComputedStyle thingamajiggy's. They should contain the 'current' style they had. What you could then do is have an array of all CSS properties you want to test and simply loop them through a function of your own that gets the CSS property for everything using forementioned methods (depending on which browser). I usually attempt the DOMNode.style[property] first as this is "inline" javascript and always rules over everything, then I sniff if the browser uses the .currentStyle method or .getComputedStyle and use the correct one.
It's not perfect and you might need to clean up some things (height: auto; to the actual current height, some browsers might return RGB colours instead of HEX) etc.
So, yes, I don't know of anything prefab that you can use in Javascript.