GVKun编程网logo

Java Swing revalidate() 与 repaint()

2

对于JavaSwingrevalidate()与repaint()感兴趣的读者,本文将会是一篇不错的选择,并为您提供关于ASP.NETCompareValidatorvalidateCurrency、

对于Java Swing revalidate() 与 repaint()感兴趣的读者,本文将会是一篇不错的选择,并为您提供关于ASP.NET CompareValidator validate Currency、c# – Invalidate()和Refresh()都调用OnPaint()、C# 验证控件的使用 RequiredFieldValidator&CompareValidator、com.intellij.psi.impl.source.tree.java.NameValuePairElement的实例源码的有用信息。

本文目录一览:

Java Swing revalidate() 与 repaint()

Java Swing revalidate() 与 repaint()

我正在组合一个 Swing 应用程序,我经常想在其中替换 JPanel
的内容。为此,我调用removeAll(),然后添加我的新内容,然后调用revalidate()

但是我发现旧内容实际上仍然可见(尽管被新内容遮盖了)。repaint()如果我在 之外添加一个调用revalidate(),它会按预期工作。

我敢肯定,在其他场合我也经历过,只要打电话revalidate()就足够了。

所以基本上我的问题是 - 我是否需要调用这两个函数,如果不需要,我应该什么时候调用它们?

答案1

小编典典

您需要调用repaint()revalidate()。前者告诉 Swing 窗口的某个区域是脏的(这是擦除被
删除的老孩子的图像所必需的removeAll());后者告诉布局管理器重新计算布局(添加组件时这是必要的)。这应该会导致面板的
项重新绘制,但可能不会导致面板本身这样做(请参阅此以获取重新绘制触发器的列表)。

在更一般的说明上:我建议不要重用原始面板,而是构建一个新面板并在父面板上交换它们。

ASP.NET CompareValidator validate Currency

ASP.NET CompareValidator validate Currency

CompareValidator HAS BUG OR I AM MISING SOMETHING ? 

I have a text Box for price then I have a compare validator. The problem here is that even if I put a number like $32000.00 it gives me the error message

I have a CompareValidator, I set the Operator=DataTypeCheck, and Type=Currency
However, on the application, if i enter $3,000.00 triggers the error message

 

<asp:CompareValidator ID="CompareValidator6" ControlTovalidate="txtPrice" Operator="DataTypeCheck" Type="Currency" runat="server" ErrorMessage="Currency Format Only Accepted For Price"></asp:CompareValidator>

<asp:CompareValidator ID="CompareValidator_txtAmount" runat="server" display="Dynamic" ErrorMessage="Amount is invalid" ControlTovalidate="txtAmount" Operator="DataTypeCheck"  Type="Currency" CultureInvariantValues="True"></asp:CompareValidator>

 

Does anyone encounter problem using the compare validator against a textBox with operator=DataTypeCheck, type="Currency" and the textBox value contains more than 2 decimal point?
With type="Double" it works fine with more than 2 decimal point but must not have comma.
Below is my test result:
Currency 10,200.20 pass
Currency 10,200.204 fail
Double 10,200.20 fail
Double 10200.204 pass
Any suggestion to overcome this issue?

 

http://www.cnblogs.com/emanlee/archive/2009/08/12/1544645.html

http://forums.asp.net/t/1277960.aspx

http://www.tech-archive.net/Archive/DotNet/microsoft.public.dotnet.faqs/2004-08/0089.html

http://www.vbdotnetforums.com/web-forms/16645-comparevalidator-currency.html

http://www.codeguru.com/forum/showthread.php?t=307614

c# – Invalidate()和Refresh()都调用OnPaint()

c# – Invalidate()和Refresh()都调用OnPaint()

我试图从第1行到第2行到下面的代码中:
using System;  
using System.Windows.Forms;  

namespace MyNameSpace  
{  
    internal class MyTextBox : System.Windows.Forms.TextBox  
    {  
        protected override void OnEnabledChanged(EventArgs e)  
        {  
            base.OnEnabledChanged(e);  
            Invalidate(); // Line #1 - can get here  
            Refresh();  
        }

       protected override void OnPaint(PaintEventArgs e)  
       {
            base.OnPaint(e);   
            System.Diagnostics.Debugger.Break(); // Line #2 - can't get here  
       }  
    }  
}

然而,似乎neiter Invalidate()和Refresh()会导致OnPaint(PaintEventArgs e)被调用.两个问题:

>为什么不起作用?
>如果它不能被修复:我只想调用OnPaint(PaintEventArgs e)为了访问e.Graphics对象 – 有没有其他的方法来做到这一点?

解决方法

要覆盖控件的绘图,您必须将样式设置为UserPaint,如下所示:
this.SetStyle(ControlStyles.UserPaint,true);

有关详细信息,请参阅:

http://msdn.microsoft.com/en-us/library/system.windows.forms.control.setstyle.aspx

UserPaint If true,the control paints itself rather than the operating system doing so. If false,the Paint event is not raised. This style only applies to classes derived from Control.

C# 验证控件的使用 RequiredFieldValidator&CompareValidator

C# 验证控件的使用 RequiredFieldValidator&CompareValidator

使用验证控件可以向服务器提交表单数据时验证表单内容,下面以 RequiredFieldValidator 和 CompareValidator 为例说明验证控件的用法

RequiredFieldValidator 用来检查必填字段 CompareValidator 控件可以用来检查数据类型或者比较大小。

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ValidationControl.aspx.cs" Inherits="WebApplication1.ValidationControl" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type ="text/css" >
        .red
        {
            color:Red ; 
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <fieldset >
        
        <legend title ="123">Product Order Form </legend>
        <asp:Label ID ="lblProductName" runat ="server" Text =" Product Name:" AssociatedControlID ="txtProductName"></asp:Label>
        <br />
        <asp:TextBox ID ="txtProductName" runat ="server" ></asp:TextBox>
        <asp:RequiredFieldValidator ID ="reqProductName" ControlToValidate="txtProductName"  runat ="server" Text ="(Require)"  CssClass ="red "  SetFocusOnError ="true"  ></asp:RequiredFieldValidator>

        <br />

        <asp:Label ID ="lblPrice" runat ="server" Text ="Price:" AssociatedControlID ="txtPrice" ></asp:Label>
        <asp:TextBox ID ="txtPrice" runat ="server"  ></asp:TextBox>
        <asp:RequiredFieldValidator ID ="reqPrice" runat ="server" ControlToValidate="txtPrice" Text ="(Require)" CssClass ="red " SetFocusOnError ="true" ></asp:RequiredFieldValidator>
        <asp:CompareValidator ID ="comPrice" runat ="server" ControlToValidate ="txtPrice" Operator ="DataTypeCheck" Text ="Invalid Value" Type ="Currency"  CssClass ="red " SetFocusOnError ="true" ></asp:CompareValidator>

        <br />
        <asp:Label ID ="lblQty" runat ="server" Text ="Qty:" AssociatedControlID ="txtQty"></asp:Label>
        <asp:TextBox ID ="txtQty" runat ="server" ></asp:TextBox>
        <asp:CompareValidator ID ="comQty" runat ="server" ControlToValidate="txtQty" Text ="Invalid Value" CssClass ="red " Display ="Dynamic"  Operator ="DataTypeCheck" Type ="Integer" SetFocusOnError ="true"  ></asp:CompareValidator>
        <br />

        <asp:Button ID ="txtSummit" runat ="server" Text ="提交" onclick="txtSummit_Click" />
        </fieldset>

        <asp:Label ID ="lblResult" runat ="server" ></asp:Label>
    </div>
    </form>
</body>
</html>
View Code
public partial class ValidationControl : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void txtSummit_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                lblResult.Text = "Product Name:" + txtProductName.Text + "<br/>" +
                    "Price:" + txtPrice.Text  + "<br/>" +
                    "Qty:" + txtQty.Text;
            }
        }
    }
View Code

例子说明:

1. 验证控件 ControlToValidate 属性用于指定需要验证的控件;

2. 验证控件的 Text 属性用于验证错误时显示错误信息,一般 Text 属性只是简单的文字,但是 Text 属性也支持 html,比如 <img src="error.gif" ali=""/> 用一个图片代替简单的文字;

3. 如果要验证信息显示红色,或者别的特殊样式,可以使用 CssClass 指定样式;

4. 验证控件的 Display 属性,Display 属性有 Dynamic、Static、None 三个值,默认 Static,

Display 为 Static 时生成的错误信息如下

<span id="reqPrice">(Require)</span>

Display 为 Dynamic 生成的错误信息为

<span id="reqPrice">(Require)</span>

两者的区别是 visibility: visible 虽然隐藏了,但还是占据窗口空间,display: none 不占窗口空间,我们应该设置 Display 为 Dynamic 这样验证信息后面的控件就不会被推倒右边

None 生成的标签如下,错误信息为空,所以不能用来显示错误提示

<span id="reqPrice"></span>

5. 验证控件默认在客户端和服务器端都进行验证,一些低端的浏览器不支持 JavaScript,所以在服务器端进行验证能保证数据的有效性。可以使用 EnableClientScript ="false" 禁用客户端验证。

6. 在带有验证控件的页面提交数据时需要检查 Page.IsValid 属性,因为假如客户端验证不生效,服务器端虽然会进行验证,但是并不会阻止数据提交,只是简单的显示错误信息,如

protected void txtSummit_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                lblResult.Text = "Product Name:" + txtProductName.Text + "<br/>" +
                    "Price:" + txtPrice.Text  + "<br/>" +
                    "Qty:" + txtQty.Text;
            }
        }

 7. 使用 SetFocusOnError ="true" 来让控件验证不通过时获取焦点,如果有几个验证控件同时设置,第一个控件或者焦点,因为同一个时间只能有一个控件获得焦点。

8. 可以使用 Page.Validators 访问所有的验证控件,或者设置特殊样式。

Page_PreRender事件发生在所有控件事件之后,Page_load事件发生在所有控件事件之前
protected void Page_PreRender(object sender, EventArgs e)
        {
            foreach (BaseValidator c in Page.Validators)
            {
                if (c.IsValid)
                    c.BackColor = System.Drawing.Color.Yellow;
                else
                    c.BackColor = System.Drawing.Color.White;
            }
        }

 

com.intellij.psi.impl.source.tree.java.NameValuePairElement的实例源码

com.intellij.psi.impl.source.tree.java.NameValuePairElement的实例源码

项目:intellij-ce-playground    文件:JavaNameValuePairType.java   
@NotNull
@Override
public ASTNode createCompositeNode() {
  return new NameValuePairElement();
}
项目:tools-idea    文件:JavaNameValuePairType.java   
@NotNull
@Override
public ASTNode createCompositeNode() {
  return new NameValuePairElement();
}
项目:consulo-java    文件:JavaNameValuePairType.java   
@NotNull
@Override
public ASTNode createCompositeNode() {
  return new NameValuePairElement();
}

今天关于Java Swing revalidate() 与 repaint()的分享就到这里,希望大家有所收获,若想了解更多关于ASP.NET CompareValidator validate Currency、c# – Invalidate()和Refresh()都调用OnPaint()、C# 验证控件的使用 RequiredFieldValidator&CompareValidator、com.intellij.psi.impl.source.tree.java.NameValuePairElement的实例源码等相关知识,可以在本站进行查询。

本文标签: