vb.net 如何制作具有只读外观的 DropDownList

发布于 2024-11-28 09:49:42 字数 306 浏览 1 评论 0原文

我正在使用 vb.net 和 vs2008 开发桌面应用程序。

我有一个 DropDownList,当信息被锁定时,我不希望它与使用交互。

但如果我禁用它,它就会变灰并且文本不容易阅读。

有没有办法使单选按钮像只读文本框一样?

我希望 DropDownList 的文本看起来是黑色的,并且本身不可单击。

在此处输入图像描述

上面显示了一个禁用的 DropDownList,其中包含灰色文本和只读文本框

I am developing desktop application using vb.net and vs2008.

I have a DropDownList that I don't want it interact with use when the info is locked.

But if I disable it, it is greyed out and the text is not easy to read.

Is there any way to make radiobutton like readonly textbox?

I want text of the DropDownList looks black and itself is not clickable.

enter image description here

The above shows a disabled DropDownList with greyed out text and a readonly textbox

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

木格 2024-12-05 09:49:42

试试这个:

Enable="false"

将其放在 标记中。

Try this:

Enable="false"

Place it within your <asp:DropDownList> tag.

心凉怎暖 2024-12-05 09:49:42

我最近遇到了类似的问题。我的解决方案是删除 DropDownList 中除所选值之外的所有其他值。这将使文本保持黑色而不是灰色。用户将能够看到现有值并单击它,但无法更改它。

希望这有帮助。

I recently encountered a similar issue. My solution was to remove all other values of the DropDownList except the one that is selected. This will keep the text as black as opposed to grey. Users will be able see the existing value and click it but will not be able to change it.

Hope this helps.

清引 2024-12-05 09:49:42

不,您不能在桌面应用程序中使用 CSS。当您通过设置Disabled=true禁用下拉列表时;或Enabled=false(无论是什么情况),您还可以更改字体属性以使其更易于阅读。您可以设置其他属性,例如 Border、BorderStyle 等。

No, you can't use CSS in a desktop app. When you disable the dropdownlist by setting Disabled=true; or Enabled=false (whatever the case is), you can also change the Font properties to make it easier to read. You can set other properties such as Border, BorderStyle, etc, etc.

温柔少女心 2024-12-05 09:49:42

保持控件启用。在 GOTFOCUS 事件中,使用 SENDKEYS 将 {tab} 发送到表单。用户将无法更改它!顺便说一句,适用于用户可以关注的所有控件。

Keep the control enabled. In the GOTFOCUS event, use SENDKEYS to send a {tab} to the form. the user will not be able to change it! By the way, workt for ALL controls, that a user can focus.

恬淡成诗 2024-12-05 09:49:42

试试这个

Private Sub ComboBox1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles ComboBox1.KeyDown
    If e.KeyCode = Keys.Delete Or e.KeyCode = Keys.Back Or ComboBox1.SelectedText.Length > 0 Then e.Handled = True
End Sub

Private Sub ComboBox1_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles ComboBox1.KeyPress
    For i = 0 To ComboBox1.Items.Count - 1
        If Not ComboBox1.Text = ComboBox1.Items(i) Then
            e.Handled = True
        End If
    Next
End Sub

Try this

Private Sub ComboBox1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles ComboBox1.KeyDown
    If e.KeyCode = Keys.Delete Or e.KeyCode = Keys.Back Or ComboBox1.SelectedText.Length > 0 Then e.Handled = True
End Sub

Private Sub ComboBox1_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles ComboBox1.KeyPress
    For i = 0 To ComboBox1.Items.Count - 1
        If Not ComboBox1.Text = ComboBox1.Items(i) Then
            e.Handled = True
        End If
    Next
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文