시작하기 런타임에서 .NET C# 보고서 컨트롤 속성을 변경하는 방법
페이지 정보
작성자 GrapeCity 작성일 2022-05-18 09:36 조회 418회 댓글 0건본문
관련링크
사용 중인 보고서의 유형, 섹션 또는 페이지/RDL에 따라 런타임에서 컨트롤 속성을 변경하는 다양한 방법이 있습니다. 이 문서에서는 각 보고서 유형의 절차를 살펴보겠습니다.
코드 기반 섹션 보고서
섹션 보고서에서 코드를 보고서 이벤트에 추가하여 런타임에서 컨트롤 속성을 변경할 수 있습니다. 예를 들어, 코드는 C# 및 VB.NET에서 레이블의 Text 속성을 변경합니다.
C#:
private void detail_Format(object sender, EventArgs e){ string s; switch (this.label1.Text){ case "1": s = "string 1"; break; case "2": s = "string 2"; break; case "3": s = "string 3"; break; default: s = "string X"; break; } this.label1.Text = s; // (**1) Move a Label control from its original location to: (X,Y) = (1,0) this.label2.Location = new System.Drawing.PointF(1,0); // (**2) Set the Font property for a Label control to: "Bold,Arial,14pt,Italic" this.label3.Font = new System.Drawing.Font("Arial", 14.0F, FontStyle.Bold | FontStyle.Italic, GraphicsUnit.Point,1); }
VB.NET:
Private Sub Detail_Format(…) Handles Detail.Format 'Change the value of the Text property for a Label control. Dim s As String Select Case Me.Label1.Text Case "1" : s = "string 1" Case "2" : s = "string 2" Case "3" : s = "string 3" Case Else : s = "string X" End Select Me.Label1.Text = s ' (**1) Move a Label control from its original location to: (X,Y) = (1,0) Me.Label2.Location = new System.Drawing.PointF(1, 0) ' (**2) Set the Font property for a Label control to: "Bold,Arial,14pt,Italic" Me.Label3.Font = new System.Drawing.Font("Arial", 14.0F, FontStyle.Bold Or FontStyle.Italic, GraphicsUnit.Point,1) End Sub
(**1) 위치 속성 값은 숫자 유형으로 나타나기 때문에 이 속성에서 반환된 위치 객체(예: Location.X)의 멤버를 직접 변경할 수 없습니다. 런타임에서 위치 속성을 변경하려면 System.Drawing.PointF 클래스의 새 인스턴스를 만들어 위치 속성의 데이터 유형과 일치시켜야 합니다.
(**2) 글꼴 속성의 값이 ReadOnly인 경우 예를 들어 Font.Name의 값을 직접 변경할 수 없습니다. 런타임에서 글꼴 속성을 변경하려면 글꼴 객체의 새 인스턴스를 만들어야 합니다.
중요 사항: 컨트롤(예: Detail_Format 또는 PageHeader_BeforePrint 또는 GroupFooter_AfterPrint)을 포함하는 섹션의 이벤트 내 또는 ReportStart 이벤트 내에서만 컨트롤의 속성을 변경할 수 있습니다. 비공개 또는 공개 수정자가 있는 보고서 외부의 코드에서 보고서 인스턴스 생성 수준의 속성을 변경할 수도 있습니다. 자세한 내용은 ActiveReports 도움말을 참조해 주시기 바랍니다.
XML 기반 섹션 보고서
XML 기반 섹션 보고서(및 최종 사용자 디자이너의 섹션 보고서)에서 스크립트를 스크립트 탭의 보고서 이벤트에 추가하여 런타임에서 컨트롤 속성을 변경할 수 있습니다. 예를 들어, 코드는 C# 및 VB.NET에서 레이블의 텍스트 속성을 변경합니다.
C#:
public void Detail_Format() { string s; switch (this.Label1.Text) { case "1": s = "string 1"; break; case "2": s = "string 2"; break; case "3": s = "string 3"; break; default: s = "string X"; break; } this.Label1.Text = s; // (**1) Move a Label control from its original location to: (X,Y) = (1,0) this.Label2.Location = new System.Drawing.PointF(1,0); // (**2) Set the Font property for a Label control to: "Bold,Arial,14pt,Italic" this.Label3.Font = new System.Drawing.Font("Arial", 14.0F, FontStyle.Bold | FontStyle.Italic, GraphicsUnit.Point,1); }
VB.NET:
Sub Detail_Format 'Change the value of the Text property for a Label control. Dim s As String Select Case Me.Label1.Text Case "1" : s = "string 1" Case "2" : s = "string 2" Case "3" : s = "string 3" Case Else : s = "string X" End Select Me.Label1.Text = s ' (**1) Move a Label control from its original location to: (X,Y) = (1,0) Me.Label2.Location = new System.Drawing.PointF(1, 0) ' (**2) Set the Font property for a Label control to: "Bold,Arial,14pt,Italic" Me.Label3.Font = new System.Drawing.Font("Arial", 14.0F, FontStyle.Bold Or FontStyle.Italic, GraphicsUnit.Point,1) End Sub
페이지 및 RDL 보고서
페이지 또는 RDL 보고서에서 코드를 컨트롤 속성의 식에 추가하여 런타임에서 컨트롤 속성을 변경할 수 있습니다. 아래에서 예시를 참조하십시오.
참고: 유형이 ExpressionInfo인 모든 속성에서 식을 설정할 수 있습니다. 하지만 위치 또는 크기와 같은 컨트롤 속성은 변경할 수 없습니다. 페이지 보고서는 WYSIWYG 출력이 있도록 설계되었으므로 런타임에서 크기 및 위치 설정을 변경할 수 없습니다.
출력 값 변경
출력 값을 변경하려면 속성 창에서 컨트롤의 값 속성을 찾고 드롭 다운 화살표 버튼을 클릭하여 <Expressions ...> 를 선택합니다. 식 편집기를 연 상태로 다음과 같은 식을 입력합니다(필드 이름을 FieldName으로 대체):
=Switch(Fields!_FieldName_.Value="1","string1", Fields!_FieldName_.Value="2","string2", Fields!_FieldName_.Value="3","string3", Fields!_FieldName_.Value<>"","stringX")
조건부 서식
조건부로 특정 값을 서식 지정하려면 예를 들어 모든 음수 값을 기울임꼴로 표시하고 Font.FontStyle 속성을 다음 식으로 설정합니다.
=IIF(Fields!_FieldName_.Value<0,"Italic","Normal")
특정 페이지에서만 표시
보고서의 최종 페이지에서만 표시하도록 필드를 설정하려면 속성 창에서 컨트롤의 값 속성을 찾고 드롭 다운 화살표를 클릭하여 <Expressions...>를 선택합니다. 식 편집기를 연 상태로 다음과 같이 식을 입력합니다.
=IIF(Globals!PageNumber=Globals!TotalPages, Fields!_FieldName_.Value,"")
페이지 및 RDL 보고서의 식 및 예시에 대한 자세한 내용은 사용자 가이드를 참고해 주시기 바랍니다.
지금 바로 ActiveReports.NET을 다운로드하여 직접 테스트해보세요!
댓글목록
등록된 댓글이 없습니다.