zoukankan      html  css  js  c++  java
  • [转]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;
    }      
  • 相关阅读:
    pip安装
    nfs
    源码方式安装软件
    自启动
    multipath
    linux永久添加和删除路由
    iscsi
    linux识别workstation磁盘的uuid
    centos镜像各种cd,dvd版本区别
    转:C# 中 MSCHART 饼状图显示百分比
  • 原文地址:https://www.cnblogs.com/icyJ/p/3178086.html
Copyright © 2011-2022 走看看