VB.NET中Xor运算符的等效函数是什么?

2026-05-06 08:151阅读0评论SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计303个文字,预计阅读时间需要2分钟。

VB.NET中Xor运算符的等效函数是什么?

获得以下方法:在Private Sub boldButton_Click(sender As System.Object, e As System.EventArgs)中,处理boldButton的点击事件。声明curFont和newFont为Font类型变量。curFont赋值为rtb.SelectionFont。如果curFont非空,则创建字体。

VB.NET中Xor运算符的等效函数是什么?

我得到了以下方法:

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,然后设置它样式=样式或粗体或删除它样式=样式和(非粗体).

本文共计303个文字,预计阅读时间需要2分钟。

VB.NET中Xor运算符的等效函数是什么?

获得以下方法:在Private Sub boldButton_Click(sender As System.Object, e As System.EventArgs)中,处理boldButton的点击事件。声明curFont和newFont为Font类型变量。curFont赋值为rtb.SelectionFont。如果curFont非空,则创建字体。

VB.NET中Xor运算符的等效函数是什么?

我得到了以下方法:

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,然后设置它样式=样式或粗体或删除它样式=样式和(非粗体).