vb.net – Xor的替代品
发布时间:2020-12-17 07:23:01 所属栏目:百科 来源:网络整理
导读:我得到了以下方法: Private Sub boldButton_Click(sender As System.Object,e As System.EventArgs) Handles boldButton.Click Dim curFont As Font Dim newFont As Font curFont = rtb.SelectionFont If curFont IsNot Nothing Then 'create the new font
我得到了以下方法:
Private Sub boldButton_Click(sender As System.Object,e As System.EventArgs) Handles boldButton.Click Dim curFont As Font Dim newFont As Font curFont = rtb.SelectionFont If curFont IsNot Nothing Then 'create the new font newFont = New Font(curFont.FontFamily,curFont.Size,curFont.Style Xor FontStyle.Bold) 'set it rtb.SelectionFont = newFont End If End Sub 目前在理解这部分代码curFont.Style Xor FontStyle.Bold时遇到的问题.在不使用运算符Xor的情况下实现相同结果的有效方法是什么? 编辑(由us2012评论)我需要替代方案吗? 我查了Xor on MSDN,但仍然无法理解boldButton_Click程序中的实现. 解决方法
按位异或切换标志.我们假设Style位域看起来像这样
00000000 ^^^ BIU (Bold,Italic,Underline) 所以FontStyle.Bold的值是: 00000100 现在Xor FontStyle.Bold会在某些东西中翻转这个东西.例: 00000111 Xor 00000100 = 00000011 (Boldness removed) 00000001 Xor 00000100 = 00000101 (Boldness added) 请注意,其他位不受影响. 由于您明确要求替代方案:您可以检查该位是否设置样式和粗体<> 0,然后设置它样式=样式或粗体或删除它样式=样式和(非粗体). (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |