2017-05-19 76 views
0

我有一個下拉列表在我的Windows窗體中有銀行名稱,我的要求是設計檢查Windows窗體,需要打印使用水晶報告...我知道我們可以使用自定義控件設置邊距...如何使用自定義的控件在Windows窗體,什麼是定製控件的目的..如何在Windows窗體中使用自定義控件?

+0

你說的是winForms,那你爲什麼用'asp.net'標記這個帖子? –

+0

張冠李戴.. – Harini

+0

你可以設計3個控件, 01)跌落下來 - 選擇銀行 02)TextBox1的 - 讓低利潤的檢查 03)TextBox2中 - 以獲得更高的利潤率爲檢查 通過所有三個值作爲參數傳遞到您的SQL查詢或水晶報表,我不認爲你需要爲你的需求定製的控制 –

回答

0

一旦你創建自定義的控制和編譯它應該在你的工具箱中顯示標題關聯到你的項目名稱下的項目。只需將它拖到您的表單就像您任何其他控制。

自定義控件的目的是封裝更復雜的功能並反覆重用。例如。如果您想使用單獨的NumericUpDown控件輸入100個三維座標,這需要很多工作來設置300個控件並將它們映射到數據對象的各個屬性。相反,您可以創建一個由3個NumericUpDown控件組成的自定義控件,這些控件可以直接綁定到Point3D對象。

+0

如何使用我的程序,這些控制。 ...你能提供我示例代碼.....如何使用? – Harini

0

創建TableLayout面板的形式,並與3個標籤 所有的銀行詳細信息添加到列表中創建用戶控件,它們與foreach循環

private void YourForm_Load(object sender, EventArgs e) 
     {   
          var uc = new CustomControl(); 
       foreach (var detail in CheckDetails) 
        {      

          var uc = new CustomControl(); 

          uc.lblBankName.Text=detail.BankName; 
          uc.lblLowerLimit.Text=detail.LLimit; 
          uc.lblHigherLimit.Text=detail.HLimit; 
          var temp = tbl_BankDtls.RowStyles[tbl_BankDtls.RowCount - 1]; 
          tbl_BankDtls.RowCount++; 
          tbl_BankDtls.RowStyles.Add(new RowStyle(SizeType.Absolute, 35));        
          tbl_BankDtls.Controls.Add(uc, 0,0); 
          this.Height += 40; 
          this.MinimumSize = new Size(this.Width, this.Height); 
        } 
     } 
+0

是第三方控制....如果有辦法,我在那裏會得到自定義控件參考文件....什麼是命名空間......因爲它拋出錯誤... – Harini

+0

沒有它不是一個第三方控制它只是一個用戶控件,您可以添加的, 右擊項目(解決方案資源管理器) - >添加 - >用戶控件 設計這是您的要求,這與上面的代碼片斷動態地添加到您的主要形式 –

+0

這3個標籤控件和表layoutpanel必須在自定義控件或Windows窗體中? – Harini

0
Form1 : (Form1.cs) 
using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 

namespace BankDetails_Test 
{ 
    public partial class Form1 : Form 
    { 
     public Form1() 
     { 
      InitializeComponent(); 
     } 

     private void button1_Click(object sender, EventArgs e) 
     { 
      var uc = new BankDtls(); 
      uc.Anchor = (AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom); 
      //uc.lblBankName.Text = detail.BankName; 
      //uc.lblLowerLimit.Text = detail.LLimit; 
      //uc.lblHigherLimit.Text = detail.HLimit; 
      //var temp = tableLayoutPanel1.RowStyles[tableLayoutPanel1.RowCount - 1]; 
      tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 40)); 
      tableLayoutPanel1.Controls.Add(uc, 0, tableLayoutPanel1.RowCount); 
      tableLayoutPanel1.SetColumnSpan(uc, 3); 
      this.Height += 40; 
      this.MinimumSize = new Size(this.Width, this.Height); 
      tableLayoutPanel1.RowCount++; 
     } 
    } 
} 


Form1 (Designer.cs) 
namespace BankDetails_Test 
{ 
    partial class Form1 
    { 
     /// <summary> 
     /// Required designer variable. 
     /// </summary> 
     private System.ComponentModel.IContainer components = null; 

     /// <summary> 
     /// Clean up any resources being used. 
     /// </summary> 
     /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> 
     protected override void Dispose(bool disposing) 
     { 
      if (disposing && (components != null)) 
      { 
       components.Dispose(); 
      } 
      base.Dispose(disposing); 
     } 

     #region Windows Form Designer generated code 

     /// <summary> 
     /// Required method for Designer support - do not modify 
     /// the contents of this method with the code editor. 
     /// </summary> 
     private void InitializeComponent() 
     { 
      this.button1 = new System.Windows.Forms.Button(); 
      this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); 
      this.label1 = new System.Windows.Forms.Label(); 
      this.label2 = new System.Windows.Forms.Label(); 
      this.label3 = new System.Windows.Forms.Label(); 
      this.tableLayoutPanel1.SuspendLayout(); 
      this.SuspendLayout(); 
      // 
      // button1 
      // 
      this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); 
      this.button1.Location = new System.Drawing.Point(306, 42); 
      this.button1.Name = "button1"; 
      this.button1.Size = new System.Drawing.Size(75, 23); 
      this.button1.TabIndex = 0; 
      this.button1.Text = "Add Another"; 
      this.button1.UseVisualStyleBackColor = true; 
      this.button1.Click += new System.EventHandler(this.button1_Click); 
      // 
      // tableLayoutPanel1 
      // 
      this.tableLayoutPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
      | System.Windows.Forms.AnchorStyles.Left) 
      | System.Windows.Forms.AnchorStyles.Right))); 
      this.tableLayoutPanel1.ColumnCount = 3; 
      this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); 
      this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33334F)); 
      this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33334F)); 
      this.tableLayoutPanel1.Controls.Add(this.label3, 2, 0); 
      this.tableLayoutPanel1.Controls.Add(this.label2, 1, 0); 
      this.tableLayoutPanel1.Controls.Add(this.label1, 0, 0); 
      this.tableLayoutPanel1.Location = new System.Drawing.Point(5, 5); 
      this.tableLayoutPanel1.Name = "tableLayoutPanel1"; 
      this.tableLayoutPanel1.RowCount = 2; 
      this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F)); 
      this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 0F)); 
      this.tableLayoutPanel1.Size = new System.Drawing.Size(376, 31); 
      this.tableLayoutPanel1.TabIndex = 1; 
      // 
      // label1 
      // 
      this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
      | System.Windows.Forms.AnchorStyles.Left) 
      | System.Windows.Forms.AnchorStyles.Right))); 
      this.label1.AutoSize = true; 
      this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 
      this.label1.Location = new System.Drawing.Point(5, 5); 
      this.label1.Margin = new System.Windows.Forms.Padding(5); 
      this.label1.Name = "label1"; 
      this.label1.Size = new System.Drawing.Size(115, 20); 
      this.label1.TabIndex = 0; 
      this.label1.Text = "Bank Name"; 
      this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; 
      // 
      // label2 
      // 
      this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
      | System.Windows.Forms.AnchorStyles.Left) 
      | System.Windows.Forms.AnchorStyles.Right))); 
      this.label2.AutoSize = true; 
      this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 
      this.label2.Location = new System.Drawing.Point(130, 5); 
      this.label2.Margin = new System.Windows.Forms.Padding(5); 
      this.label2.Name = "label2"; 
      this.label2.Size = new System.Drawing.Size(115, 20); 
      this.label2.TabIndex = 1; 
      this.label2.Text = "Lower Margin"; 
      this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; 
      // 
      // label3 
      // 
      this.label3.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
      | System.Windows.Forms.AnchorStyles.Left) 
      | System.Windows.Forms.AnchorStyles.Right))); 
      this.label3.AutoSize = true; 
      this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 
      this.label3.Location = new System.Drawing.Point(255, 5); 
      this.label3.Margin = new System.Windows.Forms.Padding(5); 
      this.label3.Name = "label3"; 
      this.label3.Size = new System.Drawing.Size(116, 20); 
      this.label3.TabIndex = 2; 
      this.label3.Text = "Higher Margin"; 
      this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; 
      // 
      // Form1 
      // 
      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 
      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 
      this.ClientSize = new System.Drawing.Size(393, 70); 
      this.Controls.Add(this.tableLayoutPanel1); 
      this.Controls.Add(this.button1); 
      this.MaximizeBox = false; 
      this.MinimizeBox = false; 
      this.Name = "Form1"; 
      this.Text = "Form1"; 
      this.tableLayoutPanel1.ResumeLayout(false); 
      this.tableLayoutPanel1.PerformLayout(); 
      this.ResumeLayout(false); 

     } 

     #endregion 

     private System.Windows.Forms.Button button1; 
     private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; 
     private System.Windows.Forms.Label label1; 
     private System.Windows.Forms.Label label3; 
     private System.Windows.Forms.Label label2; 
    } 
} 



BankDtls - UserControl (BankDtls.Designer.cs) 
namespace BankDetails_Test 
{ 
    partial class BankDtls 
    { 
     /// <summary> 
     /// Required designer variable. 
     /// </summary> 
     private System.ComponentModel.IContainer components = null; 

     /// <summary> 
     /// Clean up any resources being used. 
     /// </summary> 
     /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> 
     protected override void Dispose(bool disposing) 
     { 
      if (disposing && (components != null)) 
      { 
       components.Dispose(); 
      } 
      base.Dispose(disposing); 
     } 

     #region Component Designer generated code 

     /// <summary> 
     /// Required method for Designer support - do not modify 
     /// the contents of this method with the code editor. 
     /// </summary> 
     private void InitializeComponent() 
     { 
      this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); 
      this.comboBox1 = new System.Windows.Forms.ComboBox(); 
      this.numericUpDown1 = new System.Windows.Forms.NumericUpDown(); 
      this.numericUpDown2 = new System.Windows.Forms.NumericUpDown(); 
      this.tableLayoutPanel1.SuspendLayout(); 
      ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); 
      ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit(); 
      this.SuspendLayout(); 
      // 
      // tableLayoutPanel1 
      // 
      this.tableLayoutPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
      | System.Windows.Forms.AnchorStyles.Left) 
      | System.Windows.Forms.AnchorStyles.Right))); 
      this.tableLayoutPanel1.ColumnCount = 3; 
      this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); 
      this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); 
      this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); 
      this.tableLayoutPanel1.Controls.Add(this.numericUpDown2, 2, 0); 
      this.tableLayoutPanel1.Controls.Add(this.comboBox1, 0, 0); 
      this.tableLayoutPanel1.Controls.Add(this.numericUpDown1, 1, 0); 
      this.tableLayoutPanel1.Location = new System.Drawing.Point(5, 5); 
      this.tableLayoutPanel1.Name = "tableLayoutPanel1"; 
      this.tableLayoutPanel1.RowCount = 1; 
      this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); 
      this.tableLayoutPanel1.Size = new System.Drawing.Size(332, 31); 
      this.tableLayoutPanel1.TabIndex = 0; 
      // 
      // comboBox1 
      // 
      this.comboBox1.FormattingEnabled = true; 
      this.comboBox1.Items.AddRange(new object[] { 
      "Bank ABC", 
      "Bank XYZ", 
      "Bank DSH"}); 
      this.comboBox1.Location = new System.Drawing.Point(3, 3); 
      this.comboBox1.Name = "comboBox1"; 
      this.comboBox1.Size = new System.Drawing.Size(104, 21); 
      this.comboBox1.TabIndex = 0; 
      // 
      // numericUpDown1 
      // 
      this.numericUpDown1.Location = new System.Drawing.Point(113, 3); 
      this.numericUpDown1.Name = "numericUpDown1"; 
      this.numericUpDown1.Size = new System.Drawing.Size(104, 20); 
      this.numericUpDown1.TabIndex = 1; 
      // 
      // numericUpDown2 
      // 
      this.numericUpDown2.Location = new System.Drawing.Point(223, 3); 
      this.numericUpDown2.Name = "numericUpDown2"; 
      this.numericUpDown2.Size = new System.Drawing.Size(104, 20); 
      this.numericUpDown2.TabIndex = 2; 
      // 
      // BankDtls 
      // 
      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 
      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 
      this.Controls.Add(this.tableLayoutPanel1); 
      this.Name = "BankDtls"; 
      this.Size = new System.Drawing.Size(340, 39); 
      this.tableLayoutPanel1.ResumeLayout(false); 
      ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit(); 
      ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit(); 
      this.ResumeLayout(false); 

     } 

     #endregion 

     private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; 
     private System.Windows.Forms.NumericUpDown numericUpDown2; 
     private System.Windows.Forms.ComboBox comboBox1; 
     private System.Windows.Forms.NumericUpDown numericUpDown1; 
    } 
} 

我已經試過這樣somethink添加到表請嘗試上面提到的代碼

相關問題