如何在c#3.5中为richtextbox检查空 [英] How to check empty for richtextbox in c# 3.5

查看:107
本文介绍了如何在c#3.5中为richtextbox检查空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我如何在c#3.5中检查richtextbox为空吗

如果有人知道答案,请尽快回复

解决方案

试试这段代码

 public bool isRichTextBoxEmpty()
{
TextPointer startPointer = MyRTB1.ContentStart.GetNextInsertionPosition(LogicalDirection.Forward);
TextPointer endPointer = MyRTB1.ContentEnd.GetNextInsertionPosition(LogicalDirection.Backward);
if(startPointer.CompareTo(endPointer)== 0)
返回true;
else
返回false;
}





我从 here [ ^ ]。


< blockquote>就这么简单。



 使用系统; 
使用 System.Collections.Generic;
使用 System.ComponentModel;
使用 System.Data;
使用 System.Drawing;
使用 System.Linq;
使用 System.Text;
使用 System.Windows.Forms;

命名空间 CP_329218_How_to_check_empty_for_richtextbox_in_csharp_3_5
{
public partial class Form1:Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click( object sender,EventArgs e)
{
if (richTextBox1.Text!= String .Empty)
MessageBox.Show(richTextBox1.Text);
}
}
}







希望这有助于是然后接受并投票给答案,否则回复你的疑问

--Rahul D。



Can anybody tell me how to check richtextbox empty in c# 3.5
Please if anybody knows the answer then reply back soon

解决方案

Try this code

public bool isRichTextBoxEmpty()
{
    TextPointer startPointer = MyRTB1.ContentStart.GetNextInsertionPosition(LogicalDirection.Forward);
    TextPointer endPointer = MyRTB1.ContentEnd.GetNextInsertionPosition(LogicalDirection.Backward);
    if (startPointer.CompareTo(endPointer) == 0)
        return true;
    else
        return false;
}



I picked this up from here[^].


As simple as that .

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CP_329218_How_to_check_empty_for_richtextbox_in_csharp_3_5
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (richTextBox1.Text !=String.Empty)
            MessageBox.Show(richTextBox1.Text);
        }
    }
}




Hope this helps if yes then accept and vote the answer otherwise revert back with your queries
--Rahul D.



这篇关于如何在c#3.5中为richtextbox检查空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆