none
Radiobutton 控件当FlatStyle设置为System后的问题 RRS feed

  • 问题

  • Radiobutton 控件FlatStyle设置为System后,当鼠标点下 不放开一个未被选中的Radiobutton并拖动鼠标离开该Radiobutton,此时该Radiobutton获取焦点有虚线框但没有被check(如下面链接图中的Radiobutton2),切换到其他画面,再切换回来时,该Radiobutton 就会自动check,如何不让它自动check?

    http://www.bigant.net/2014-06-23_113533.png

    2014年6月23日 5:21

答案

  • Radiobutton 控件FlatStyle设置为System后,当鼠标点下 不放开一个未被选中的Radiobutton并拖动鼠标离开该Radiobutton,此时该Radiobutton获取焦点有虚线框但没有被check(如下面链接图中的Radiobutton2),切换到其他画面,再切换回来时,该Radiobutton 就会自动check,如何不让它自动check?

    http://www.bigant.net/2014-06-23_113533.png

    Hi,

    你可以在它的move_leave事件中对所有的radiobutton检索并设置activecontrol为已经选中的radiobutton, 目的是不让这个未选中的radiobutton成为这个forum的activeControl, 这样就可以让这个控件在form再次获取到窗口时不再被选中并改变checked的值。

    Public Class Form1
        Dim lsRdb As List(Of RadioButton)
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            lsRdb = New List(Of RadioButton) From {RadioButton1, RadioButton2, RadioButton3, RadioButton4}
            For Each rdb As RadioButton In lsRdb
                rdb.FlatStyle = FlatStyle.System
                AddHandler rdb.MouseLeave, AddressOf RadioButton_MouseLeave
            Next
        End Sub
    
        Private Sub RadioButton_MouseLeave(sender As Object, e As EventArgs)
            For Each rdb As RadioButton In lsRdb
                If rdb.Checked Then
                    Me.ActiveControl = rdb
                End If
            Next
        End Sub
    End Class

    效果图:

    1. 问题重现:

     

    2. 添加事件处理后的效果:

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2014年6月24日 6:47
    版主

全部回复

  • Radiobutton 控件FlatStyle设置为System后,当鼠标点下 不放开一个未被选中的Radiobutton并拖动鼠标离开该Radiobutton,此时该Radiobutton获取焦点有虚线框但没有被check(如下面链接图中的Radiobutton2),切换到其他画面,再切换回来时,该Radiobutton 就会自动check,如何不让它自动check?

    http://www.bigant.net/2014-06-23_113533.png

    Hi,

    你可以在它的move_leave事件中对所有的radiobutton检索并设置activecontrol为已经选中的radiobutton, 目的是不让这个未选中的radiobutton成为这个forum的activeControl, 这样就可以让这个控件在form再次获取到窗口时不再被选中并改变checked的值。

    Public Class Form1
        Dim lsRdb As List(Of RadioButton)
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            lsRdb = New List(Of RadioButton) From {RadioButton1, RadioButton2, RadioButton3, RadioButton4}
            For Each rdb As RadioButton In lsRdb
                rdb.FlatStyle = FlatStyle.System
                AddHandler rdb.MouseLeave, AddressOf RadioButton_MouseLeave
            Next
        End Sub
    
        Private Sub RadioButton_MouseLeave(sender As Object, e As EventArgs)
            For Each rdb As RadioButton In lsRdb
                If rdb.Checked Then
                    Me.ActiveControl = rdb
                End If
            Next
        End Sub
    End Class

    效果图:

    1. 问题重现:

     

    2. 添加事件处理后的效果:

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2014年6月24日 6:47
    版主
  • 上面的效果和想要实现的还有差距,鼠标离开时切换动作明显,客户已确认接受自动check的现象,还是感谢解答!
    2014年7月7日 11:56