📄 winform.pas.~3~
字号:
unit WinForm;
interface
uses
System.Drawing, System.Collections, System.ComponentModel,
System.Windows.Forms, System.Data;
type
TWinForm = class(System.Windows.Forms.Form)
{$REGION 'Designer Managed Code'}
strict private
/// <summary>
/// Required designer variable.
/// </summary>
Components: System.ComponentModel.Container;
Label1: System.Windows.Forms.Label;
GroupBox1: System.Windows.Forms.GroupBox;
TextBox1: System.Windows.Forms.TextBox;
CheckBox1: System.Windows.Forms.CheckBox;
CheckBox2: System.Windows.Forms.CheckBox;
CheckBox3: System.Windows.Forms.CheckBox;
GroupBox2: System.Windows.Forms.GroupBox;
RadioButton1: System.Windows.Forms.RadioButton;
RadioButton2: System.Windows.Forms.RadioButton;
RadioButton3: System.Windows.Forms.RadioButton;
rtbTest: System.Windows.Forms.RichTextBox;
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
procedure InitializeComponent;
procedure CheckBox1_CheckedChanged(sender: System.Object; e: System.EventArgs);
procedure rtbTest_SelectionChanged(sender: System.Object; e: System.EventArgs);
procedure CheckBox2_CheckedChanged(sender: System.Object; e: System.EventArgs);
procedure CheckBox3_CheckedChanged(sender: System.Object; e: System.EventArgs);
procedure RadioButton1_CheckedChanged(sender: System.Object; e: System.EventArgs);
procedure RadioButton2_CheckedChanged(sender: System.Object; e: System.EventArgs);
procedure RadioButton3_CheckedChanged(sender: System.Object; e: System.EventArgs);
{$ENDREGION}
strict protected
/// <summary>
/// Clean up any resources being used.
/// </summary>
procedure Dispose(Disposing: Boolean); override;
private
{ Private Declarations }
public
constructor Create;
end;
[assembly: RuntimeRequiredAttribute(TypeOf(TWinForm))]
implementation
{$AUTOBOX ON}
{$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>
procedure TWinForm.InitializeComponent;
begin
Self.Label1 := System.Windows.Forms.Label.Create;
Self.GroupBox1 := System.Windows.Forms.GroupBox.Create;
Self.CheckBox3 := System.Windows.Forms.CheckBox.Create;
Self.CheckBox2 := System.Windows.Forms.CheckBox.Create;
Self.CheckBox1 := System.Windows.Forms.CheckBox.Create;
Self.TextBox1 := System.Windows.Forms.TextBox.Create;
Self.GroupBox2 := System.Windows.Forms.GroupBox.Create;
Self.RadioButton3 := System.Windows.Forms.RadioButton.Create;
Self.RadioButton2 := System.Windows.Forms.RadioButton.Create;
Self.RadioButton1 := System.Windows.Forms.RadioButton.Create;
Self.rtbTest := System.Windows.Forms.RichTextBox.Create;
Self.GroupBox1.SuspendLayout;
Self.GroupBox2.SuspendLayout;
Self.SuspendLayout;
//
// Label1
//
Self.Label1.Location := System.Drawing.Point.Create(16, 32);
Self.Label1.Name := 'Label1';
Self.Label1.Size := System.Drawing.Size.Create(64, 16);
Self.Label1.TabIndex := 0;
Self.Label1.Text := '当前字体';
//
// GroupBox1
//
Self.GroupBox1.Controls.Add(Self.CheckBox3);
Self.GroupBox1.Controls.Add(Self.CheckBox2);
Self.GroupBox1.Controls.Add(Self.CheckBox1);
Self.GroupBox1.Controls.Add(Self.TextBox1);
Self.GroupBox1.Controls.Add(Self.Label1);
Self.GroupBox1.Location := System.Drawing.Point.Create(8, 8);
Self.GroupBox1.Name := 'GroupBox1';
Self.GroupBox1.Size := System.Drawing.Size.Create(248, 112);
Self.GroupBox1.TabIndex := 1;
Self.GroupBox1.TabStop := False;
Self.GroupBox1.Text := '文字样式';
//
// CheckBox3
//
Self.CheckBox3.Location := System.Drawing.Point.Create(168, 72);
Self.CheckBox3.Name := 'CheckBox3';
Self.CheckBox3.Size := System.Drawing.Size.Create(64, 24);
Self.CheckBox3.TabIndex := 4;
Self.CheckBox3.Text := '下划线';
Include(Self.CheckBox3.CheckedChanged, Self.CheckBox3_CheckedChanged);
//
// CheckBox2
//
Self.CheckBox2.Location := System.Drawing.Point.Create(96, 72);
Self.CheckBox2.Name := 'CheckBox2';
Self.CheckBox2.Size := System.Drawing.Size.Create(56, 24);
Self.CheckBox2.TabIndex := 3;
Self.CheckBox2.Text := '斜体';
Include(Self.CheckBox2.CheckedChanged, Self.CheckBox2_CheckedChanged);
//
// CheckBox1
//
Self.CheckBox1.Location := System.Drawing.Point.Create(24, 72);
Self.CheckBox1.Name := 'CheckBox1';
Self.CheckBox1.Size := System.Drawing.Size.Create(56, 24);
Self.CheckBox1.TabIndex := 2;
Self.CheckBox1.Text := '粗体';
Include(Self.CheckBox1.CheckedChanged, Self.CheckBox1_CheckedChanged);
//
// TextBox1
//
Self.TextBox1.Location := System.Drawing.Point.Create(72, 24);
Self.TextBox1.Name := 'TextBox1';
Self.TextBox1.Size := System.Drawing.Size.Create(160, 21);
Self.TextBox1.TabIndex := 1;
Self.TextBox1.Text := '';
//
// GroupBox2
//
Self.GroupBox2.Controls.Add(Self.RadioButton3);
Self.GroupBox2.Controls.Add(Self.RadioButton2);
Self.GroupBox2.Controls.Add(Self.RadioButton1);
Self.GroupBox2.Location := System.Drawing.Point.Create(264, 8);
Self.GroupBox2.Name := 'GroupBox2';
Self.GroupBox2.Size := System.Drawing.Size.Create(80, 112);
Self.GroupBox2.TabIndex := 2;
Self.GroupBox2.TabStop := False;
Self.GroupBox2.Text := '段落格式';
//
// RadioButton3
//
Self.RadioButton3.Location := System.Drawing.Point.Create(8, 80);
Self.RadioButton3.Name := 'RadioButton3';
Self.RadioButton3.Size := System.Drawing.Size.Create(64, 24);
Self.RadioButton3.TabIndex := 2;
Self.RadioButton3.Text := '右对齐';
Include(Self.RadioButton3.CheckedChanged, Self.RadioButton3_CheckedChanged);
//
// RadioButton2
//
Self.RadioButton2.Location := System.Drawing.Point.Create(8, 24);
Self.RadioButton2.Name := 'RadioButton2';
Self.RadioButton2.Size := System.Drawing.Size.Create(64, 24);
Self.RadioButton2.TabIndex := 1;
Self.RadioButton2.Text := '左对齐';
Include(Self.RadioButton2.CheckedChanged, Self.RadioButton2_CheckedChanged);
//
// RadioButton1
//
Self.RadioButton1.Location := System.Drawing.Point.Create(8, 52);
Self.RadioButton1.Name := 'RadioButton1';
Self.RadioButton1.Size := System.Drawing.Size.Create(56, 24);
Self.RadioButton1.TabIndex := 0;
Self.RadioButton1.Text := '居中';
Include(Self.RadioButton1.CheckedChanged, Self.RadioButton1_CheckedChanged);
//
// rtbTest
//
Self.rtbTest.Location := System.Drawing.Point.Create(8, 128);
Self.rtbTest.Name := 'rtbTest';
Self.rtbTest.Size := System.Drawing.Size.Create(336, 152);
Self.rtbTest.TabIndex := 3;
Self.rtbTest.Text := 'RichTextBox1';
Include(Self.rtbTest.SelectionChanged, Self.rtbTest_SelectionChanged);
//
// TWinForm
//
Self.AutoScaleBaseSize := System.Drawing.Size.Create(6, 14);
Self.ClientSize := System.Drawing.Size.Create(352, 285);
Self.Controls.Add(Self.rtbTest);
Self.Controls.Add(Self.GroupBox2);
Self.Controls.Add(Self.GroupBox1);
Self.Name := 'TWinForm';
Self.Text := '简易文本编辑器';
Self.GroupBox1.ResumeLayout(False);
Self.GroupBox2.ResumeLayout(False);
Self.ResumeLayout(False);
end;
{$ENDREGION}
procedure TWinForm.Dispose(Disposing: Boolean);
begin
if Disposing then
begin
if Components <> nil then
Components.Dispose();
end;
inherited Dispose(Disposing);
end;
constructor TWinForm.Create;
begin
inherited Create;
//
// Required for Windows Form Designer support
//
InitializeComponent;
//
// TODO: Add any constructor code after InitializeComponent call
//
end;
procedure TWinForm.RadioButton3_CheckedChanged(sender: System.Object; e: System.EventArgs);
begin
if RadioButton3.Checked then
rtbTest.SelectionAlignment := HorizontalAlignment.Right;
end;
procedure TWinForm.RadioButton2_CheckedChanged(sender: System.Object; e: System.EventArgs);
begin
if RadioButton2.Checked then
rtbTest.SelectionAlignment := HorizontalAlignment.Left ;
end;
procedure TWinForm.RadioButton1_CheckedChanged(sender: System.Object; e: System.EventArgs);
begin
if RadioButton1.Checked then
rtbTest.SelectionAlignment := HorizontalAlignment.Center;
end;
procedure TWinForm.CheckBox3_CheckedChanged(sender: System.Object; e: System.EventArgs);
var
oldFont:System.Drawing.Font;
NewFontStyle: FontStyle;
begin
rtbTest.Focus;
oldFont := rtbTest.SelectionFont;
if CheckBox3.Checked then
NewFontStyle := oldFont.Style or FontStyle.Underline
else
NewFontStyle := oldFont.Style xor FontStyle.Underline;
rtbTest.SelectionFont := System.Drawing.Font.Create(oldFont.Name,
oldFont.Size, NewFontStyle);
end;
procedure TWinForm.CheckBox2_CheckedChanged(sender: System.Object; e: System.EventArgs);
var
oldFont:System.Drawing.Font;
NewFontStyle: FontStyle;
begin
rtbTest.Focus;
oldFont := rtbTest.SelectionFont;
if CheckBox2.Checked then
NewFontStyle := oldFont.Style or FontStyle.Italic
else
NewFontStyle := oldFont.Style xor FontStyle.Italic;
rtbTest.SelectionFont := System.Drawing.Font.Create(oldFont.Name,
oldFont.Size, NewFontStyle);
end;
procedure TWinForm.rtbTest_SelectionChanged(sender: System.Object; e: System.EventArgs);
var
oldFont:System.Drawing.Font;
NewFontStyle: FontStyle;
begin
rtbTest.Focus;
oldFont := rtbTest.SelectionFont;
CheckBox1.Checked :=oldFont.Bold;
CheckBox2.Checked :=oldFont.Italic;
CheckBox3.Checked :=oldFont.Underline;
RadioButton1.Checked :=rtbTest.SelectionAlignment=HorizontalAlignment.Center;
RadioButton2.Checked :=rtbTest.SelectionAlignment=HorizontalAlignment.Left;
RadioButton3.Checked :=rtbTest.SelectionAlignment=HorizontalAlignment.Right;
end;
procedure TWinForm.CheckBox1_CheckedChanged(sender: System.Object; e: System.EventArgs);
var
oldFont:System.Drawing.Font;
NewFontStyle: FontStyle;
begin
rtbTest.Focus;
oldFont := rtbTest.SelectionFont;
if CheckBox1.Checked then
NewFontStyle := oldFont.Style or FontStyle.Bold
else
NewFontStyle := oldFont.Style xor FontStyle.Bold;
rtbTest.SelectionFont := System.Drawing.Font.Create(oldFont.Name,
oldFont.Size, NewFontStyle);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -