如何更改RichTextBox大小的文本并删除文本上的突出显示?

时间:2015-05-31 21:21:25

标签: c# .net winforms richtextbox

这是我的代码。当我打开文本文件时,它会改变文本的字体大小,然后着色所有文本,使其高亮,就像我选择所有文本一样。

string s = richTextBox1.Text;
richTextBox1.Clear();
richTextBox1.Text = s;

我试着添加这个:

this.richTextBox.SelectionStart = 0;
this.richTextBox.SelectionLength = richTextBox.Text.Length;     
this.richTextBox.SelectionBackColor = Color.White;

它做了诀窍,但问题是文本现在回到原来的小尺寸。 我之前也试过添加它:

{{1}}

但是这没有做到。

1 个答案:

答案 0 :(得分:2)

您正在直接更改Text属性:<?php require_once("./includes/database_connection.php"); error_reporting(E_ALL); ini_set('display_errors', 1); $query = "SELECT customerNumber, customerName, contactLastName, contactFirstName, phone, addressLine1, addressLine2, city, state, postalCode, country, salesRepEmployeeNumber, creditLimit FROM customers ORDER BY customerNumber ASC"; $result = mysqli_query($dbc, $query) or die ('Error querying database'); ?> <!DOCTYPE html> <html> <head> <meta charset='utf-8'> <title>Home</title> <link type="text/css" rel="stylesheet" href="classic_cars.css" /> <style> #table2{ width: 100px; height: 50px; padding: 50px; } </style> </head> <div> <body> <?php require_once("./includes/navigation.php"); ?> <div id="table2"> <table border= "1"> <tr> <td>customerNumber</td> <td>customerName</td> <td>contactLastName</td> <td>contactFirstName</td> <td>phone</td> <td>addressLine1</td> <td>addressLine2</td> <td>city</td> <td>state</td> <td>postalCode</td> <td>country</td> <td>salesRepEmployeeNumber</td> <td>creditLimit</td> </tr> <?php while($row = mysqli_fetch_array($result)) { $customer_number = $row['customerNumber']; $customer_name = $row['customerName']; $contact_last_name = $row['contactLastName']; $contact_first_name = $row['contactFirstName']; $phone_number = $row['phone']; $address_1 = $row['addressLine1']; $address_2 = $row['addressLine2']; $city = $row['city']; $state = $row['state']; $postal_code = $row['postalCode']; $country = $row['country']; $salesrep_number = $row['salesRepEmployeeNumber']; $credit_limit = $row['creditLimit']; echo "<tr> <td>$customer_number</td> <td>$customer_name</td> <td>$contact_last_name</td> <td>$contact_first_name</td> <td>$phone_number</td> <td>$address_1</td> <td>$address_2</td> <td>$city </td> <td>$state</td> <td>$postal_code</td> <td>$country</td> <td>$salesrep_number</td> <td>$credit_limit</td> </tr>"; } // end while loop ?> </table> </div> <?php require_once("./includes/footer.php"); ?> </body> </html> 如果您不想弄乱任何格式,请不要这样做或richTextBox1.Text = s;。有关规则,请参阅here

更改此

richTextBox1.Text = File.ReadAllText(filename);

到此:

        if (theDialog.ShowDialog() == DialogResult.OK)
        {
            string filename = theDialog.FileName;
            richTextBox1.Text = File.ReadAllText(filename);
            this.richTextBox1.SelectionStart = 0;
            this.richTextBox1.SelectionLength = this.richTextBox1.Text.Length;
            this.richTextBox1.SelectionFont = new System.Drawing.Font("Maiandra GD", 30);
            string s = richTextBox1.Text;
            richTextBox1.Clear();
            richTextBox1.Text = s;
        }

我不知道&#39;突出显示&#39;你提到但是当你在选择之外插入文本时,它可能会将文本恢复为默认字体&amp;您之前设置的属性..