C# 获取c中html元素的实际边距#

C# 获取c中html元素的实际边距#,c#,html,computed-style,C#,Html,Computed Style,在我的c代码中,我需要得到IHTMlements边距占用的实际像素数。我查看了它的style和currentStyle成员,但相关部分要么为null,要么设置为“auto” 搜索互联网在javascript中显示了getCurrentStyle函数,但我需要在我的c#代码中使用这些数字 显然,我对js和html以及所有东西都有点陌生 那么,有没有办法得到c代码中元素边距(或其任何其他度量)使用的实际计算像素数 我忘了补充一句:这只会在可预见的将来在Internet Explorer中使用它必须在

在我的c代码中,我需要得到IHTMlements边距占用的实际像素数。我查看了它的style和currentStyle成员,但相关部分要么为null,要么设置为“auto”

搜索互联网在javascript中显示了getCurrentStyle函数,但我需要在我的c#代码中使用这些数字

显然,我对js和html以及所有东西都有点陌生

那么,有没有办法得到c代码中元素边距(或其任何其他度量)使用的实际计算像素数


我忘了补充一句:这只会在可预见的将来在Internet Explorer中使用

它必须在C代码中吗?在客户端,通过脚本执行此操作可能更容易—例如,与的某些组合,并应返回边距。

它必须在C代码中吗?通过脚本在客户端实现这一点可能更容易—例如,与的一些组合,并应返回边距。

Javascript部分

var elementToCalc=document.getElementById(“您的元素”)

HTML部分

Javascript部分

var elementToCalc=document.getElementById(“您的元素”)

HTML部分


从offsetWidth中减去IHTMLElement2.clientWidth怎么样

有关指标的更多详细信息:

从偏移宽度中减去IHTMLElement2.clientWidth怎么样

有关指标的更多详细信息:

我想我需要能够访问c中的数字。我正在使用很多现有的代码,我无法重新构建体系结构或类似的东西。有可能在脚本中生成我需要的数字,然后在c#中访问吗?我也是一个完全的新手,所以要注意我说的:但是从c#中访问JS结果的一种方法是JS将其结果写入DOM(例如,作为DOM中隐藏文本节点的值)。我想我需要能够在c#中访问这些数字。我正在使用很多现有的代码,我无法重新构建体系结构或类似的东西。有可能在脚本中生成我需要的数字,然后在c#中访问吗?我也是一个完全的新手,所以请注意我说的:但是从c#访问JS结果的一种方法是JS将其结果写入DOM(例如,作为DOM中隐藏文本节点的值)。
document.getElementById('txtHidMarginTop').value = parseInt ( elementToCalc.currentStyle.marginTop );
document.getElementById('txtHidMarginLeft').value = parseInt ( elementToCalc.currentStyle.marginLeft;
document.getElementById('txtHidMarginRight').value = parseInt ( elementToCalc.currentStyle.marginRight;
document.getElementById('txtHidMarginBottom').value = parseInt ( elementToCalc.currentStyle.marginBottom );
<input type='hidden' id='txtHidMarginTop' runat='server' />
<input type='hidden' id='txtHidMarginLeft' runat='server' />
<input type='hidden' id='txtHidMarginBottom' runat='server' />
<input type='hidden' id='txtHidMarginRight' runat='server' />
 string marginTop = int.Parse ( txtHidMarginTop.Value );
    string marginLeft = int.Parse ( txtHidMarginLeft.Value );
    string marginRight = int.Parse ( txtHidMarginRight.Value );
    string marginBottom = int.Parse ( txtHidMarginBottom.Value );