我正在尝试设置一个可以改变标题栏内写作的条件......
但是如何更改标题栏文字?
答案 0 :(得分:105)
要在运行时更改表单的标题,我们可以编码如下
public partial class FormMain : Form
{
public FormMain()
{
InitializeComponent();
this.Text = "This Is My Title";
}
}
答案 1 :(得分:51)
您可以使用Text
属性更改Windows窗体标题栏中的文本。
// This class is added to the namespace containing the Form1 class.
class MainApplication
{
public static void Main()
{
// Instantiate a new instance of Form1.
Form1 f1 = new Form1();
// Display a messagebox. This shows the application
// is running, yet there is nothing shown to the user.
// This is the point at which you customize your form.
System.Windows.Forms.MessageBox.Show("The application "
+ "is running now, but no forms have been shown.");
// Customize the form.
f1.Text = "Running Form";
// Show the instance of the form modally.
f1.ShowDialog();
}
}
答案 2 :(得分:1)
SQL> select * from t$loader;
T1 T2 T3 T4 T5
---------- ---------- ---------- ---------- ----------
1 2 2 2 3
4 5 5 5 6
7 8 8 8 9
I was having some problems with inserting date and time into the name of the form. Finally found the error. I'm posting this in case anyone has the same problem and doesn't have to spend years googling solutions.
答案 3 :(得分:1)
包括从Form
类创建新对象的所有答案都绝对会创建新的form
。但是您可以在Text
类中使用ActiveForm
子类的Form
属性。例如:
public Form1()
{
InitializeComponent();
Form1.ActiveForm.Text = "Your Title";
}
答案 4 :(得分:0)
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
//private void Form1_Load(object sender, EventArgs e)
//{
// // Instantiate a new instance of Form1.
// Form1 f1 = new Form1();
// f1.Text = "zzzzzzz";
//}
}
class MainApplication
{
public static void Main()
{
// Instantiate a new instance of Form1.
Form1 f1 = new Form1();
// Display a messagebox. This shows the application
// is running, yet there is nothing shown to the user.
// This is the point at which you customize your form.
System.Windows.Forms.MessageBox.Show("The application "
+ "is running now, but no forms have been shown.");
// Customize the form.
f1.Text = "Running Form";
// Show the instance of the form modally.
f1.ShowDialog();
}
}
}
答案 5 :(得分:0)
this.Text = "Your Text Here"
将其放置在Initialize Component(初始化组件)下,它应在表单加载时更改。
答案 6 :(得分:0)
如果您以后想更新它,一旦“ this”不再引用它,我很幸运可以分配一个变量以指向主窗体。
static Form f0;
public OrdUpdate()
{
InitializeComponent();
f0=this;
}
// then later you can say
f0.Text="New text";