我有一個下拉列表在我的Windows窗體中有銀行名稱,我的要求是設計檢查Windows窗體,需要打印使用水晶報告...我知道我們可以使用自定義控件設置邊距...如何使用自定義的控件在Windows窗體,什麼是定製控件的目的..如何在Windows窗體中使用自定義控件?
0
A
回答
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
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添加到表請嘗試上面提到的代碼
相關問題
- 1. Windows窗體 - 自定義用戶控件
- 2. 在Windows窗體中使用WPF自定義控件?
- 3. 如何在Windows窗體中旋轉自定義控件
- 4. 使用自定義控件複製/粘貼到Windows窗體中
- 5. 定義一個Windows窗體自定義控件的事件
- 6. 如何將Windows窗體控件應用於WPF自定義控件庫?
- 7. C#窗體中的自定義控件Windows窗體鼠標事件問題
- 8. 使用自定義組件中的控件處理事件Windows窗體
- 9. 如何在Windows窗體中自定義選項卡控件喜歡Dropbox的Dropbox?
- 10. Windows窗體 - 自定義MaskedTextBox
- 11. 自定義Windows窗體(表)
- 12. 如何在c中自定義窗體控件#
- 13. Windows窗體中的自定義選項卡控件
- 14. Wicket - 如何在自定義窗體組件中使用ListView?
- 15. 自定義控件屬性 - C#,窗體
- 16. 如何使Windows窗體控件只讀?
- 17. Windows窗體標籤自定義控件來源更改
- 18. 自定義系統菜單欄控件(windows窗體)
- 19. Windows窗體自定義控件沒有正確繪畫
- 20. 在Windows窗體控件上使用RectVisible
- 21. 如何在C#Windows窗體中創建自定義ToolStripProgressBar?
- 22. 如何在ListBox Windows窗體中創建自定義項目?
- 23. 如何在Windows窗體中使用DataRepeater控件和XML?
- 24. 如何在Windows窗體中使用MVVM來顯示WPF控件
- 25. 如何使用Windows窗體在Window Titlebar中繪製自定義按鈕?
- 26. .NET Windows窗體自定義控件,如何創建快捷菜單
- 27. 如何將Windows窗體設計器支持添加到自定義控件?
- 28. C#窗體窗體自定義控件跨線程操作
- 29. 如何引用圖表Windows窗體控件中的特定點?
- 30. 如何在Windows窗體中實現控件的固定位置?
你說的是winForms,那你爲什麼用'asp.net'標記這個帖子? –
張冠李戴.. – Harini
你可以設計3個控件, 01)跌落下來 - 選擇銀行 02)TextBox1的 - 讓低利潤的檢查 03)TextBox2中 - 以獲得更高的利潤率爲檢查 通過所有三個值作爲參數傳遞到您的SQL查詢或水晶報表,我不認爲你需要爲你的需求定製的控制 –