我一直在寻找解决问题的方法,但一直找不到,所以我想在这里问。
我有一个用户窗体,上面有多个文本框被禁用,因此用户无法编辑它们。而且我注意到excel将禁用的文本框的字体颜色更改为浅灰色。因此,我一直在尝试将字体颜色改回黑色,以便于阅读,但无法这样做。我尝试将属性窗口中的ForeColor更改为黑色,并且尝试通过代码进行操作,例如
<script type="text/javascript">
var val1, val2, val3;
function slider1Change(valArg){
val1 = valArg;
document.getElementById('slider1Status').innerHTML = val1;
}
function slider2Change(valArg){
val2 = valArg;
document.getElementById('slider2Status').innerHTML = val2;
}
function slider3Change(valArg){
val3 = valArg;
document.getElementById('slider3Status').innerHTML = val3;
}
function finalCalc(val4){
document.getElementById('finalCalc').innerHTML = val1 + val2 + val3;
}
</script>
<form>
<div class="form-group">
<label for="formControlRange">Number of Sales:</label> <span id="slider1Status">50</span>
<input type="range" class="form-control-range" onInput="slider1Change(this.value)">
</div>
<div class="form-group">
<label for="formControlRange">Number of Transactions:</label> <span id="slider2Status">50</span>
<input type="range" class="form-control-range" onInput="slider2Change(this.value)">
</div>
<div class="form-group">
<label for="formControlRange">Number of Returns:</label> <span id="slider3Status">50</span>
<input type="range" class="form-control-range" onInput="slider3Change(this.value)">
</div>
</form>
<h2>You could be saving $<span id="finalCalc">50</span> per month by switching to CompanyX</h2>
但是文本框仍然保持浅灰色。有什么办法可以改变吗?
编辑:我还考虑过将文本框更改为标签,但这需要大量工作,这很好,但是我希望找到另一个潜在的解决方案。
答案 0 :(得分:1)
您可以像这样使用.locked
属性
Private Sub UserForm_Click()
custom_lock Me.TextBox1
End Sub
Private Sub UserForm_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
custom_unlock Me.TextBox1
End Sub
Function custom_lock(tb As MSForms.TextBox)
tb.ForeColor = vbRed
tb.Locked = True
End Function
Function custom_unlock(tb As MSForms.TextBox)
tb.ForeColor = vbBlack
tb.Locked = False
End Function