• [转]C# RichTextBox不用滚动条


    转自:http://blog.csdn.net/happy09li/article/details/7444912

    第一种思路:

    richTextBox1.ScrollBars = RichTextBoxScrollBars.None;
    richTextBox.ContentsResized += new ContentsResizedEventHandler(richTextBox_ContentsResized);
    
    private void richTextBox1_ContentsResized(object sender, ContentsResizedEventArgs e)
    {
        richTextBox1.Height = e.NewRectangle.Height + 10;
    }

    第二种思路:

    1.先调用以下方法:

    [DllImport("user32.dll", EntryPoint = "SendMessageA")]
    private static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, string lParam);

    2.设置RichTextBox:            

    this.richTextBox1 = new RichTextBox();           
    this.richTextBox1.Text = "contentcontentcontentcontentcontentcontentcontentcontentcontent";
    this.richTextBox1.Width = this.pPanel.Width-15;
    this.richTextBox1.ScrollBars = RichTextBoxScrollBars.None;
    this.richTextBox1.Location = new Point(0, 0 + this.lab1.Height+10);
    //得到RichTextBox高度
    int EM_GETLINECOUNT = 0x00BA;//获取总行数的消息号 
    int lc = SendMessage(this.richTextBox1.Handle, EM_GETLINECOUNT, IntPtr.Zero, "");
    int sf = this.richTextBox1.Font.Height * (lc + 1) + this.richTextBox1.Location.Y;
    this.richTextBox1.Height = sf;
    this.richTextBox1.Resize += new EventHandler(richTextBox1_Resize);
    this.Controls.Add(this.richTextBox1);

    3.设置RichTextBox的Resize:

    void richTextBox1_Resize(object sender, EventArgs e)
    {
        int EM_GETLINECOUNT = 0x00BA;//获取总行数的消息号 
        int lc = SendMessage(this.richTextBox1.Handle, EM_GETLINECOUNT, IntPtr.Zero, "");
        int sf = this.richTextBox1.Font.Height * (lc + 1) + this.richTextBox1.Location.Y;
        this.richTextBox1.Height = sf;
    }      
  • 相关阅读:
    mongo数据更新(修改器)
    mongo数据排序和分页显示
    mongodb数据操作(CRUD)
    mongodb配置和基本操作
    lua语法基本
    awk常见基本使用
    sed命令常见用法
    Python(面向对象编程4——继承顺序、封装)
    Python(面向对象3 ——实例)
    Python(面向对象编程——2 继承、派生、组合、抽象类)
  • 原文地址:https://www.cnblogs.com/icyJ/p/3178086.html
Copyright © 2020-2023  润新知