Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在Gtk中使用粗体、斜体和下划线按钮,也就是如何在Gtk中动态设置文本格式_C#_Textview_Tags_Gtk - Fatal编程技术网

C# 如何在Gtk中使用粗体、斜体和下划线按钮,也就是如何在Gtk中动态设置文本格式

C# 如何在Gtk中使用粗体、斜体和下划线按钮,也就是如何在Gtk中动态设置文本格式,c#,textview,tags,gtk,C#,Textview,Tags,Gtk,也许这是一个有点宽泛或模糊的问题 我在网上找不到任何对我有意义的东西,我正在使用Gtk2.0和C#,关于如何在网上实现这一点的每一个参考都是用不同的语言编写的,似乎只是一个函数名列表,或者在从代码生成文本时在文本视图中只有格式化文本的示例(例如,制作一个句子“Hello World”)然后将hello设置为bold。似乎没有人在谈论如何实现这一点,这似乎是一个非常基本的功能 将某些文本加粗非常容易,例如: protected void Command_bold(object sender, Ev

也许这是一个有点宽泛或模糊的问题

我在网上找不到任何对我有意义的东西,我正在使用Gtk2.0和C#,关于如何在网上实现这一点的每一个参考都是用不同的语言编写的,似乎只是一个函数名列表,或者在从代码生成文本时在文本视图中只有格式化文本的示例(例如,制作一个句子“Hello World”)然后将hello设置为bold。似乎没有人在谈论如何实现这一点,这似乎是一个非常基本的功能

将某些文本加粗非常容易,例如:

protected void Command_bold(object sender, EventArgs e)
{
    if (selectedTextView.Buffer.GetSelectionBounds(out A, out B))
    {
        selectedTextView.Buffer.ApplyTag("bold", A, B);
    }
}
但是,当我用一个按钮触发此功能时,它只会使内容加粗(或斜体…等)。加粗按钮的正常功能会使所有选择都加粗(如果部分或全部选择都不加粗),或者如果所有选择都加粗,则使所有选择都不加粗


那么,如何在Gtk TextView对象中检测文本是否为粗体?

好的,我想出来了。或多或少。下面的逻辑有缺陷,但这是一种检测标记和控制粗体按钮逻辑的方法:

protected void Action_Bold(object sender, EventArgs e)
{
    TextIter iA, A, B;
    bool isBold = false;
    if (selectedTextView.Buffer.GetSelectionBounds(out A, out B))
    {
        iA = A;
        while (iA.Compare(B) < 0)
        {
            foreach (TextTag tag in A.Tags)
            {
                if (tag.Name == "bold") isBold = true;
            }

            iA.ForwardChar();

        }

        if (isBold == true)
        {
            selectedTextView.Buffer.RemoveTag("bold", A, B);
        }
        else
        {
            selectedTextView.Buffer.ApplyTag("bold", A, B);
        }
    }
}
受保护的无效操作\u粗体(对象发送方,事件参数e)
{
TextIter iA,A,B;
bool-isBold=false;
if(selectedTextView.Buffer.GetSelectionBounds(out A,out B))
{
iA=A;
而(iA.比较(B)<0)
{
foreach(A.Tags中的TextTag标记)
{
如果(tag.Name==“bold”)isBold=true;
}
iA.ForwardChar();
}
如果(isBold==true)
{
选择TextView.Buffer.RemoveTag(“粗体”,A,B);
}
其他的
{
选择TextView.Buffer.ApplyTag(“粗体”,A,B);
}
}
}