小编Dot*_*ude的帖子

需要使用javascript将选定的文本设置为粗体/斜体/下划线,并使用c#保存和检​​索相同的文本

我需要使用javascript制作文本框粗体/斜体/下划线的选定文本.为此,我使用以下代码.

<img src="~/images/Bold"  alt="Bold" onclick="changeFont('TextBox1','b');"  />
<img src="~/images/Italic" alt="Italic" onclick="changeFont('TextBox1','i');"  />
<img src="~/images/Underline" alt="Underline" onclick="changeFont('TextBox1','u');"  />
Run Code Online (Sandbox Code Playgroud)

<script type="text/javascript" language="javascript">
    function changeFont(txt, change) {
        if (change == 'b') {
            if (document.getElementById(txt).style.fontWeight == 'bold')
                document.getElementById(txt).style.fontWeight = 'normal';
            else
                document.getElementById(txt).style.fontWeight = 'bold';
        }
        else if (change == 'i') {
            if (document.getElementById(txt).style.fontStyle == 'italic')
                document.getElementById(txt).style.fontStyle = 'normal';
            else
                document.getElementById(txt).style.fontStyle = 'italic';
        }
        else {
            if (document.getElementById(txt).style.textDecoration == 'underline')
                document.getElementById(txt).style.textDecoration = 'none';
            else
                document.getElementById(txt).style.textDecoration = 'underline';
        }
    }
</script>
Run Code Online (Sandbox Code Playgroud)

但是这里的问题是,当我点击粗体图像时,它会将整个文本变为粗体而不是所选文本.它也不适用于其他两个图像.

保存文本框的文本时,即使尝试使用,我也无法获取包含html标签的文本

document.getElementById('TextBox1').innerHTML;
Run Code Online (Sandbox Code Playgroud)

我只能获得文本框的值.

有没有办法使用javascript或C#保存和检​​索相同的内容

在此先感谢SC

javascript c# bold

5
推荐指数
1
解决办法
3万
查看次数

如何在c#中使用"打开/保存文件"对话框时防止资源泄漏

我们在桌面应用程序(C#)中使用save/opn文件对话框.当我们第一次打开对话框时,句柄增加100.关闭对话框后,句柄不会减少.从下一次起,手柄增加10左右,减少2到4.

我们尝试通过调用dispose并使其为null来减少句柄.并尝试使用块.但他们都没有解决这个问题.

你能告诉我任何解决方法吗?或者我们可以使用任何自定义控件

请就此提出建议

提前致谢

代码:代码是

SaveFileDialog objSaveDialog = new SaveFileDialog();
try
{

    objSaveDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
    objSaveDialog.Title = "Save to Text File";
    //objSaveDialog.ShowDialog();
    DialogResult dlgResult = objSaveDialog.ShowDialog();
    objSaveDialog.Dispose();
    if (dlgResult == DialogResult.OK)
    {
        string strSaveFilePath = objSaveDialog.FileName;

        if (!string.IsNullOrEmpty(strSaveFilePath))
        {
            TextWriter myTxtWriter = new StreamWriter(strSaveFilePath, false);
            for (int index = 0; index < 10000; index++)
            {
                myTxtWriter.WriteLine("sample text.....................................");
            }

            myTxtWriter.Flush();
            myTxtWriter.Close();
            myTxtWriter.Dispose();

        }
    }
}
finally
{
    if (objSaveDialog != null)
    {
        objSaveDialog = null;
        //((IDisposable)objSaveDialog).Dispose(); …
Run Code Online (Sandbox Code Playgroud)

c# openfiledialog resource-leak

2
推荐指数
1
解决办法
1838
查看次数

标签 统计

c# ×2

bold ×1

javascript ×1

openfiledialog ×1

resource-leak ×1