ASPxHtmlEditor调整文本内部的大小

时间:2013-09-09 13:54:11

标签: c# asp.net visual-studio-2012 devexpress

我似乎无法找到一种方法来调整ASPxHtmlEditor的内部文本。应该没有滚动条,所有文本应始终可见。文本从后面的代码加载。所以我输入的文字越多,控件应该越大。有人请帮忙。

编辑:文本在页面加载时已知,如果可能,这可以在服务器端完成。

 <dx:ASPxHtmlEditor ID="txtMessageBody" ClientInstanceName="txtMessageBody" runat="server"
                Height="50px" Width="740px" ActiveView="Preview">
                <Toolbars>
                </Toolbars>
                <Settings AllowHtmlView="false" AllowPreview="true" AllowDesignView="false" />
                <SettingsHtmlEditing EnterMode="BR"   />
 </dx:ASPxHtmlEditor>

1 个答案:

答案 0 :(得分:0)

所以我设法找到了办法。不是最优雅的方式,但绝对给了我预期和需要的结果:

protected void Page_Load(object sender, EventArgs e)
{
    DataTable dtMsg = new DataTable();

    string strConn = cConnection.GetConnectionString();
    SqlConnection conn = new SqlConnection(strConn);

    SqlCommand sqlCMD = new SqlCommand("GetHomeMessage", conn);

    sqlCMD.CommandType = CommandType.StoredProcedure;

    sqlCMD.Parameters.Add("@Lang", SqlDbType.VarChar).Value = "Afrikaans";


    SqlDataAdapter sdaStat = new SqlDataAdapter(sqlCMD);

    sdaStat.Fill(dtMsg);

    if (dtMsg.Rows != null && dtMsg.Rows.Count > 0)
    {
        txtMessageBody.Html = dtMsg.Rows[0][0].ToString();

        MemoryStream stream = new MemoryStream();

        txtMessageBody.Export(DevExpress.Web.ASPxHtmlEditor.HtmlEditorExportFormat.Txt, stream);

        stream.Position = 0;
        StreamReader reader = new StreamReader(stream);
        string msgBody = reader.ReadToEnd();
        msgBody = msgBody.Trim();
        stream.Close();
        reader.Close();

        Font font = new Font("Arial", 16, FontStyle.Regular);

        Size size = TextRenderer.MeasureText(msgBody, font);

        txtMessageBody.Height = size.Height;

        txtMessageBody.SettingsResize.AllowResize = true;
        txtMessageBody.SettingsResize.MinWidth = 740;
    }
}