我只是想用“ X”按钮创建一个非常小的表单。
当我执行全部操作时,它比应该做的要大: 在Visual Studio设计编辑器上:
但是运行时会显示:
设计者代码:
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.BackColor = System.Drawing.Color.Black;
this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.button1.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.button1.ForeColor = System.Drawing.Color.Gray;
this.button1.Location = new System.Drawing.Point(6, 7);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(27, 26);
this.button1.TabIndex = 0;
this.button1.Text = "X";
this.button1.UseVisualStyleBackColor = false;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form3
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.ClientSize = new System.Drawing.Size(40, 40);
this.Controls.Add(this.button1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "Form3";
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.ResumeLayout(false);
}
我做错了什么?
答案 0 :(得分:4)
您可能会看到以下设计器代码,因为缺少设置按钮和表单的某些属性。
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.BackColor = System.Drawing.Color.Black;
this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.button1.Font = new System.Drawing.Font("Arial", 12F,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
((byte)(0)));
this.button1.ForeColor = System.Drawing.Color.Gray;
this.button1.Location = new System.Drawing.Point(0, 0);
this.button1.Name = "button1";
this.button1.AutoSize = true; //you were missing this for the button
this.button1.Size = new System.Drawing.Size(27, 26);
this.button1.TabIndex = 0;
this.button1.Text = "X";
this.button1.UseVisualStyleBackColor = false;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoSize = true; //you were missing this for the form
this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;//also this
this.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.ClientSize = new System.Drawing.Size(40, 40);
this.Controls.Add(this.button1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.ResumeLayout(false);
}
请检查上面的设计师代码,并且该代码有效。
答案 1 :(得分:0)
我认为您应该尝试将表单的class Account(MPTTModel):
""" Represents an account
An account may have a parent, and may have zero or more children. Only root
accounts can have an account_type, all child accounts are assumed to have the same
account_type as their parent.
An account's balance is calculated as the sum of all of the transaction Leg's
referencing the account.
Attributes:
uuid (SmallUUID): UUID for account. Use to prevent leaking of IDs (if desired).
name (str): Name of the account. Required.
parent (Account|None): Parent account, none if root account
code (str): Account code. Must combine with account codes of parent
accounts to get fully qualified account code.
account_type (str):Also identified as account classification - Type of account as defined by :attr:`Account.TYPES`. Can only be set on
root accounts. Child accounts are assumed to have the same type as their parent.
TYPES (Choices): Available account types. Uses ``Choices`` from ``django-model-utils``. Types can be
accessed in the choice field ``Account.TYPES.asset``, ``Account.TYPES.expense``, etc.
is_bank_account (bool): Is this a bank account. This implies we can import bank statements into #TODO implement bank statement import in future
it and that it only supports a single currency.
"""
TYPES = Choices(
("AS", "asset", "Asset"), # Eg. Cash in bank
("LI", "liability", "Liability"), # Eg. Loans, bills paid after the fact (in arrears)
("IN", "income", "Income"), # Eg. Sales, housemate contributions
("EX", "expense", "Expense"), # Eg. Office supplies, paying bills
("EQ", "equity", "Equity"), # Eg. Money from shares
("TR", "trading", "Currency Trading"), # Used to represent currency conversions
("OR", "operating_revenues", "Operating Revenues"),
("OX", "operating_expenses", "Operating Expenses"),
("NR", "nonoperating_revenues", "Non-Operating Revenues"),
("NX", "nonoperating_expenses", "Non-Operating Expenses"),
)
uuid = SmallUUIDField(default=uuid_default(), editable=False)
name = models.CharField(max_length=255,blank=True, null=True)
parent = TreeForeignKey(
"self",
null=True,
blank=True,
related_name="children",
db_index=True,
on_delete=models.CASCADE,
)
code = models.CharField(max_length=3, null=True, blank=True)
full_code = models.CharField(max_length=100, db_index=True, unique=True, null=True, blank=True)
account_type = models.CharField(max_length=255,choices=TYPES, blank=True)
# is_bank_account = models.BooleanField(default=False, blank=True,)
currencies = ArrayField(models.CharField(max_length=255, db_index=True))
organization = models.IntegerField(null=False, blank=False)
objects = AccountManager.from_queryset(AccountQuerySet)()
和Size.Width
手动设置为所需的格式。
希望有帮助!