Mono C# TextView 没有 Text属性

9 篇文章 0 订阅
1 篇文章 0 订阅

最近逐渐向Linux系统转型,但由于自己不想抛弃学习一段时间的C#语言(主要入门没C++难),了解到了Mono这个开源项目,于是转向Mono开发。
但是,开始的第一步就出现了情况,就如标题所说,Mono C# TextView 没有 Text属性,于是经过几天的研究,找到了解决方法
在这里插入图片描述

测试/调试平台

系统:Ubuntu 20.04.1 LTS
编辑器:MonoDevelop 5.10(使用阿里云Ubuntu源安装)
在这里插入图片描述
在这里插入图片描述

解决方法

在官方文档查看时,偶然发现一行代码,给我了启发(https://www.monodevelop.com/documentation/stetic-gui-designer/):

protected virtual void OnOpen(object sender, System.EventArgs e)
{
   // Reset the logTreeView and change the window back to original size
   int width, height;
   this.GetDefaultSize( out width, out height );
   this.Resize( width, height );

   logTextView.Buffer.Text = "";

   // Create and display a fileChooserDialog
   FileChooserDialog chooser = new FileChooserDialog(
      "Please select a logfile to view ...",
      this,
      FileChooserAction.Open,
      "Cancel", ResponseType.Cancel,
      "Open", ResponseType.Accept );

   if( chooser.Run() == ( int )ResponseType.Accept )
   {
      // Open the file for reading.
      System.IO.StreamReader file =
      System.IO.File.OpenText( chooser.Filename );

      // Copy the contents into the logTextView
      logTextView.Buffer.Text = file.ReadToEnd();

      // Set the MainWindow Title to the filename.
      this.Title = "Nate's Log Viewer -- " + chooser.Filename.ToString();

      // Make the MainWindow bigger to accomodate the text in the logTextView
      this.Resize( 640, 480 );

      // Close the file so as to not leave a mess.
      file.Close();
   } // end if
   chooser.Destroy();
} // end method OnOpen

For the OnClose method:

protected virtual void OnClose(object sender, System.EventArgs e)
{
   // Reset the logTreeView and change the window back to original size
   int width, height;
   this.GetDefaultSize( out width, out height );
   this.Resize( width, height );

   logTextView.Buffer.Text = "";

   // Change the MainWindow Title back to the default.
   this.Title = "Nate's Log Viewer";
} // end method OnClose

其中logTextView.Buffer.Text = "";这一行代码给我了启发,因为在官方文档里,logTextView是一个TextView控件,且这是赋值代码
在这里插入图片描述所以,将上方代码修改如下:

Build ();
textview1.Buffer.Text = "Text";

在这里插入图片描述
即可成功编译。
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

gfdgd xi

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值