表单上的按钮不起作用或显示任何文本
Button on form not working or showing any text
我正在尝试为我的表单创建自定义标题栏。为此,我有:
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
我放置了两个用于最小化和关闭的自定义按钮:
// Close
//
this.Close.BackColor = System.Drawing.Color.Black;
this.Close.FlatAppearance.BorderColor = System.Drawing.Color.White;
this.Close.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.Close.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.Close.ForeColor = System.Drawing.SystemColors.ButtonFace;
this.Close.Location = new System.Drawing.Point(376, 0);
this.Close.Name = "Close";
this.Close.Size = new System.Drawing.Size(27, 23);
this.Close.TabIndex = 1;
this.Close.Text = "X";
this.Close.UseVisualStyleBackColor = false;
this.Close.Click += new System.EventHandler(this.Close_Click);
//
// Hide
//
this.Hide.BackColor = System.Drawing.SystemColors.ControlText;
this.Hide.FlatAppearance.BorderColor = System.Drawing.Color.White;
this.Hide.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.Hide.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.Hide.ForeColor = System.Drawing.SystemColors.ButtonFace;
this.Hide.Location = new System.Drawing.Point(346, 0);
this.Hide.Name = "Hide";
this.Hide.Size = new System.Drawing.Size(30, 23);
this.Hide.TabIndex = 0;
this.Hide.Text = "---";
this.Hide.UseVisualStyleBackColor = true;
应该是这样的:
但是,出于某种原因,当我 运行 应用程序时,它们看起来像这样(没有文字):
此外,我对其进行了编码,以便在单击 Close
按钮时,此代码为 运行:
private void Close_Click(object sender, EventArgs e)
{
this.Close();
}
但是,当我点击关闭时没有任何反应。
任何人都可以指出我的代码有什么问题。或者我必须添加什么来修复它。
编辑:
原来,当我将按钮颜色更改为红色时,十字显示出来了,但它是黑色的,而不是白色的!
你可以尝试更换你喜欢的
this.Close.ForeColor = System.Drawing.SystemColors.ButtonFace;
和
lblExample.ForeColor = System.Drawing.Color.White;
首先您需要更改关闭和隐藏的设计名称。
将Close
和Hide
改成其他名称。否则将namespace
与Form 的Hide 和Form 的Close 冲突。还要记住,如果没有 FormBorderStyle
,您将无法像往常一样移动表格..
试试看,这至少对我有用。
注意:更改是我将控件放置在我希望它们看到的位置,而不是使用绘图
public Mainform()
{
InitializeComponent();
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
// Close
//
this.CloseBut.BackColor = System.Drawing.Color.Black;
this.CloseBut.FlatAppearance.BorderColor = System.Drawing.Color.White;
this.CloseBut.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.CloseBut.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.CloseBut.ForeColor = System.Drawing.SystemColors.ButtonFace;
//this.CloseBut.Location = new System.Drawing.Point(376, 0);
this.CloseBut.Name = "Close";
this.CloseBut.Size = new System.Drawing.Size(27, 23);
this.CloseBut.TabIndex = 1;
this.CloseBut.Text = "X";
this.CloseBut.UseVisualStyleBackColor = false;
this.CloseBut.Click += new System.EventHandler(this.Close_Click);
//
// Hide
//
this.HideBut.BackColor = System.Drawing.SystemColors.ControlText;
this.HideBut.FlatAppearance.BorderColor = System.Drawing.Color.White;
this.HideBut.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.HideBut.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.HideBut.ForeColor = System.Drawing.SystemColors.ButtonFace;
//this.HideBut.Location = new System.Drawing.Point(346, 0);
this.HideBut.Name = "Hide";
this.HideBut.Size = new System.Drawing.Size(30, 23);
this.HideBut.TabIndex = 0;
this.HideBut.Text = "---";
this.HideBut.UseVisualStyleBackColor = true;
this.HideBut.Click += new EventHandler(this.hide_click);
}
private void hide_click(object sender, EventArgs e)
{
this.WindowState=FormWindowState.Minimized;
}
private void Close_Click(object sender, EventArgs e)
{
this.Close();
}
有效 perfectly.I 已尝试 it.I 正在附加所有文件 请更改命名空间并尝试。
Designer.cs代码
namespace WindowsFormsApplication1
{
部分 class Form3
{
///
/// 必需的设计器变量。
///
私有 System.ComponentModel.IContainer 组件 = 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.Close = new System.Windows.Forms.Button();
this.Hide = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// Close
//
this.Close.BackColor = System.Drawing.Color.Black;
this.Close.FlatAppearance.BorderColor = System.Drawing.Color.White;
this.Close.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.Close.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.Close.ForeColor = System.Drawing.SystemColors.ButtonFace;
this.Close.Location = new System.Drawing.Point(260, 0);
this.Close.Name = "Close";
this.Close.Size = new System.Drawing.Size(27, 23);
this.Close.TabIndex = 1;
this.Close.Text = "X";
this.Close.UseVisualStyleBackColor = false;
this.Close.Click += new System.EventHandler(this.Close_Click);
//
// Hide
//
this.Hide.BackColor = System.Drawing.SystemColors.ControlText;
this.Hide.FlatAppearance.BorderColor = System.Drawing.Color.White;
this.Hide.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.Hide.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.Hide.ForeColor = System.Drawing.SystemColors.ButtonFace;
this.Hide.Location = new System.Drawing.Point(230, 0);
this.Hide.Name = "Hide";
this.Hide.Size = new System.Drawing.Size(30, 23);
this.Hide.TabIndex = 0;
this.Hide.Text = "---";
this.Hide.UseVisualStyleBackColor = true;
//
// Form3
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 262);
this.Controls.Add(this.Hide);
this.Controls.Add(this.Close);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "Form3";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Form3";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button Close;
private System.Windows.Forms.Button Hide;
}
}
点击关闭按钮
private void Close_Click(object sender, EventArgs e)
{
this.Close();
}
点击关闭按钮我已经完成了关闭代码 form.It 也有效。
我遇到了同样的问题,我的文本框在我的一个项目中没有显示文本,而它在所有其他项目中都有效。我发现我的按钮字体颜色以某种方式更改为与按钮默认颜色相同的颜色,所以文本就在那里,只是不可见。
我正在尝试为我的表单创建自定义标题栏。为此,我有:
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
我放置了两个用于最小化和关闭的自定义按钮:
// Close
//
this.Close.BackColor = System.Drawing.Color.Black;
this.Close.FlatAppearance.BorderColor = System.Drawing.Color.White;
this.Close.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.Close.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.Close.ForeColor = System.Drawing.SystemColors.ButtonFace;
this.Close.Location = new System.Drawing.Point(376, 0);
this.Close.Name = "Close";
this.Close.Size = new System.Drawing.Size(27, 23);
this.Close.TabIndex = 1;
this.Close.Text = "X";
this.Close.UseVisualStyleBackColor = false;
this.Close.Click += new System.EventHandler(this.Close_Click);
//
// Hide
//
this.Hide.BackColor = System.Drawing.SystemColors.ControlText;
this.Hide.FlatAppearance.BorderColor = System.Drawing.Color.White;
this.Hide.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.Hide.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.Hide.ForeColor = System.Drawing.SystemColors.ButtonFace;
this.Hide.Location = new System.Drawing.Point(346, 0);
this.Hide.Name = "Hide";
this.Hide.Size = new System.Drawing.Size(30, 23);
this.Hide.TabIndex = 0;
this.Hide.Text = "---";
this.Hide.UseVisualStyleBackColor = true;
应该是这样的:
但是,出于某种原因,当我 运行 应用程序时,它们看起来像这样(没有文字):
此外,我对其进行了编码,以便在单击 Close
按钮时,此代码为 运行:
private void Close_Click(object sender, EventArgs e)
{
this.Close();
}
但是,当我点击关闭时没有任何反应。
任何人都可以指出我的代码有什么问题。或者我必须添加什么来修复它。
编辑:
原来,当我将按钮颜色更改为红色时,十字显示出来了,但它是黑色的,而不是白色的!
你可以尝试更换你喜欢的
this.Close.ForeColor = System.Drawing.SystemColors.ButtonFace;
和
lblExample.ForeColor = System.Drawing.Color.White;
首先您需要更改关闭和隐藏的设计名称。
将Close
和Hide
改成其他名称。否则将namespace
与Form 的Hide 和Form 的Close 冲突。还要记住,如果没有 FormBorderStyle
,您将无法像往常一样移动表格..
试试看,这至少对我有用。
注意:更改是我将控件放置在我希望它们看到的位置,而不是使用绘图
public Mainform()
{
InitializeComponent();
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
// Close
//
this.CloseBut.BackColor = System.Drawing.Color.Black;
this.CloseBut.FlatAppearance.BorderColor = System.Drawing.Color.White;
this.CloseBut.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.CloseBut.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.CloseBut.ForeColor = System.Drawing.SystemColors.ButtonFace;
//this.CloseBut.Location = new System.Drawing.Point(376, 0);
this.CloseBut.Name = "Close";
this.CloseBut.Size = new System.Drawing.Size(27, 23);
this.CloseBut.TabIndex = 1;
this.CloseBut.Text = "X";
this.CloseBut.UseVisualStyleBackColor = false;
this.CloseBut.Click += new System.EventHandler(this.Close_Click);
//
// Hide
//
this.HideBut.BackColor = System.Drawing.SystemColors.ControlText;
this.HideBut.FlatAppearance.BorderColor = System.Drawing.Color.White;
this.HideBut.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.HideBut.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.HideBut.ForeColor = System.Drawing.SystemColors.ButtonFace;
//this.HideBut.Location = new System.Drawing.Point(346, 0);
this.HideBut.Name = "Hide";
this.HideBut.Size = new System.Drawing.Size(30, 23);
this.HideBut.TabIndex = 0;
this.HideBut.Text = "---";
this.HideBut.UseVisualStyleBackColor = true;
this.HideBut.Click += new EventHandler(this.hide_click);
}
private void hide_click(object sender, EventArgs e)
{
this.WindowState=FormWindowState.Minimized;
}
private void Close_Click(object sender, EventArgs e)
{
this.Close();
}
有效 perfectly.I 已尝试 it.I 正在附加所有文件 请更改命名空间并尝试。
Designer.cs代码
namespace WindowsFormsApplication1
{ 部分 class Form3 { /// /// 必需的设计器变量。 /// 私有 System.ComponentModel.IContainer 组件 = 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.Close = new System.Windows.Forms.Button();
this.Hide = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// Close
//
this.Close.BackColor = System.Drawing.Color.Black;
this.Close.FlatAppearance.BorderColor = System.Drawing.Color.White;
this.Close.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.Close.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.Close.ForeColor = System.Drawing.SystemColors.ButtonFace;
this.Close.Location = new System.Drawing.Point(260, 0);
this.Close.Name = "Close";
this.Close.Size = new System.Drawing.Size(27, 23);
this.Close.TabIndex = 1;
this.Close.Text = "X";
this.Close.UseVisualStyleBackColor = false;
this.Close.Click += new System.EventHandler(this.Close_Click);
//
// Hide
//
this.Hide.BackColor = System.Drawing.SystemColors.ControlText;
this.Hide.FlatAppearance.BorderColor = System.Drawing.Color.White;
this.Hide.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.Hide.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.Hide.ForeColor = System.Drawing.SystemColors.ButtonFace;
this.Hide.Location = new System.Drawing.Point(230, 0);
this.Hide.Name = "Hide";
this.Hide.Size = new System.Drawing.Size(30, 23);
this.Hide.TabIndex = 0;
this.Hide.Text = "---";
this.Hide.UseVisualStyleBackColor = true;
//
// Form3
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 262);
this.Controls.Add(this.Hide);
this.Controls.Add(this.Close);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "Form3";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Form3";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button Close;
private System.Windows.Forms.Button Hide;
}
}
点击关闭按钮
private void Close_Click(object sender, EventArgs e)
{
this.Close();
}
点击关闭按钮我已经完成了关闭代码 form.It 也有效。
我遇到了同样的问题,我的文本框在我的一个项目中没有显示文本,而它在所有其他项目中都有效。我发现我的按钮字体颜色以某种方式更改为与按钮默认颜色相同的颜色,所以文本就在那里,只是不可见。