简体   繁体   English

颜色对话框显示在浏览器后面

[英]Color Dialog Displays behind browser

I created a ASP.NET Web Forms Application and when I click on my button to display the color dialog it works correctly on first click.我创建了一个 ASP.NET Web 窗体应用程序,当我单击按钮以显示颜色对话框时,它在第一次单击时正常工作。 Subsequent clicks the dialog box displays behind the browser.随后单击该对话框显示在浏览器后面。 I noticed from some posts people had placed a color dialog on their form.我从一些帖子中注意到人们在他们的表单上放置了一个颜色对话框。 I'm not sure why, but the color dialog is no where in my toolbox.我不知道为什么,但颜色对话框不在我的工具箱中。 Looking forward to the answer to see my ID-10-T mistake.期待看到我的ID-10-T错误的答案。 Thanks!谢谢!

    protected void Button1_Click(object sender, EventArgs e)
    {
        ColorDialog colorDialog = new ColorDialog();
        colorDialog.AnyColor = true;
        colorDialog.AllowFullOpen = false;

        if (colorDialog.ShowDialog() == DialogResult.OK)
        {
            string str = null;
            str = colorDialog.Color.Name;

            if (str.Substring(0, 2) == "ff")
            {
                str = "#" + str.Substring(2);
            }

            //MessageBox.Show(str);
            lblTo.ForeColor = System.Drawing.ColorTranslator.FromHtml(str);
            lblFrom.ForeColor = System.Drawing.ColorTranslator.FromHtml(str);
            lblDate.ForeColor = System.Drawing.ColorTranslator.FromHtml(str);
            lblTime.ForeColor = System.Drawing.ColorTranslator.FromHtml(str);

            pnlKudos.BackColor = System.Drawing.ColorTranslator.FromHtml(str);
            pnlKudos.ForeColor = System.Drawing.ColorTranslator.FromHtml(str);
            txtButWait.BorderColor = System.Drawing.ColorTranslator.FromHtml(str);

            string sTemp = "border: 0px #fff solid;";
            txtExtra.Attributes["style"] = sTemp;
            sTemp = "border-bottom: 1px " + str + " solid;";
            txtExtra.Attributes["style"] = sTemp;
            sTemp = "background-color: " + str;
            divKudos.Attributes["style"] = sTemp;
        }
    }

You are showing the dialog box on the server .您正在服务器上显示对话框。

It appears to work when you run the code from Visual Studio, but that's only because the server and the client happen to be the same machine in that instance.当您从 Visual Studio 运行代码时,它似乎可以工作,但这只是因为在该实例中服务器和客户端碰巧是同一台机器。

As soon as you deploy your code to a real server, the code will stop working.一旦您将代码部署到真实服务器上,代码就会停止工作。 If you're lucky, you'll get an exception telling you that you cannot show a dialog box from a non-interactive process.如果幸运的话,您会收到一个异常,告诉您无法从非交互式进程中显示对话框。 If not, your code will hang waiting for someone to log in to the server and close the dialog box.如果没有,您的代码将挂起,等待有人登录服务器并关闭对话框。

You need to use a client-side colour picker.您需要使用客户端颜色选择器。 Google has lots of examples - eg:谷歌有很多例子 - 例如:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM