📄 c++ builder 程序设计实用教程 - 6_2 多页窗体设计 - 张晋 - 17xie.htm
字号:
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">用于存储曲线绘制的起始点,而</SPAN><SPAN
lang=EN-US>x2</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">、</SPAN><SPAN
lang=EN-US>y2</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">则用于存储正弦曲线绘制的当前点,变量</SPAN><SPAN
lang=EN-US>n</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">用于控件曲线绘制的长度;然后程序通过语句</SPAN><SPAN
lang=EN-US>Form1->Image1->Canvas->MoveTo((x2),(y2));</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">把当前绘图坐标移动到绘图的起始点;最后通过一个循环中的</SPAN><SPAN
lang=EN-US>Form1->Image1->Canvas->LineTo((x2) ,(y2));</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">语句完成绘制正弦曲线的操作。</SPAN></P>
<H4><SPAN lang=EN-US>4</SPAN><SPAN
style="FONT-FAMILY: 楷体_GB2312; mso-ascii-font-family: 'Times New Roman'">.运行程序</SPAN></H4>
<P class=MsoNormalIndent><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">按照附后的程序清单添加代码。</SPAN></P>
<P class=MsoNormalIndent><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">做完以上各步的工作后,选择菜单</SPAN><SPAN
lang=EN-US>File</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中的</SPAN><SPAN
lang=EN-US>Save All</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">选项,在弹出的对话框中选择合适的文件名保存文件,然后在键盘上按功能键【</SPAN><SPAN
lang=EN-US>F9</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">】运行程序,在程序运行的初始画面中可以选择四个标签页,并且单击上面的</SPAN><SPAN
lang=EN-US>Image</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">控件,就可以绘制出相应的曲线,程序运行结果如图</SPAN><SPAN
lang=EN-US>6-7</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">所示。</SPAN></P>
<P class=a><SPAN lang=EN-US><IMG height=221
src="C++ Builder 程序设计实用教程 - 6_2 多页窗体设计 - 张晋 - 17xie.files/6420d9b183.jpg"
width=293 v:shapes="_x0000_i1026"></SPAN></P>
<P class=MsoCaption><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">图</SPAN><SPAN
lang=EN-US>6-7<SPAN style="mso-spacerun: yes"> </SPAN></SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">程序运行结果</SPAN></P>
<P class=MsoNormalIndent><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在这个程序运行的过程中,用户可以选择四种不同的曲线——“正弦曲线”、“余弦曲线”、“正切曲线”和“余切曲线”。</SPAN></P>
<P class=MsoNormalIndent><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">程序的完整源代码如下所示:</SPAN></P>
<DIV
style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 0cm; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 0cm; PADDING-BOTTOM: 1pt; BORDER-LEFT: windowtext 1pt solid; PADDING-TOP: 1pt; BORDER-BOTTOM: windowtext 1pt solid; mso-border-alt: solid windowtext .5pt; mso-element: para-border-div">
<P class=a0
style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: medium none; PADDING-LEFT: 0cm; PADDING-BOTTOM: 0cm; BORDER-LEFT: medium none; PADDING-TOP: 0cm; BORDER-BOTTOM: medium none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 1.0pt 0cm 1.0pt 0cm"><SPAN
style="FONT-FAMILY: 仿宋_GB2312; mso-ascii-font-family: 'Times New Roman'">程序清单</SPAN><SPAN
lang=EN-US
style="FONT-SIZE: 9pt; mso-bidi-font-size: 10.0pt"><o:p></o:p></SPAN></P></DIV>
<P class=a1><SPAN lang=EN-US
style="FONT-FAMILY: 'Times New Roman'">//-----------------------------------------------------------------------<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'">#include
<vcl.h><o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'">#pragma
hdrstop<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'">#include
"math.h"<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'">#include
"Page.h"<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US
style="FONT-FAMILY: 'Times New Roman'">//-----------------------------------------------------------------------<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'">#pragma
package(smart_init)<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'">#pragma
resource "*.dfm"<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'">TForm1
*Form1;<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US
style="FONT-FAMILY: 'Times New Roman'">//-----------------------------------------------------------------------<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'">__fastcall
TForm1::TForm1(TComponent* Owner)<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><SPAN
style="mso-spacerun: yes"> </SPAN>:
TForm(Owner)<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US
style="FONT-FAMILY: 'Times New Roman'">{<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US
style="FONT-FAMILY: 'Times New Roman'">}<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US
style="FONT-FAMILY: 'Times New Roman'">//-----------------------------------------------------------------------<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US
style="FONT-FAMILY: 'Times New Roman'"><o:p> </o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'">void
__fastcall TForm1::Image1Click(TObject *Sender)<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US
style="FONT-FAMILY: 'Times New Roman'">{<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'">float
x1;<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'">float
y1;<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'">float
x2;<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'">float
y2;<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'">float
n;<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US
style="FONT-FAMILY: 'Times New Roman'">//</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">定义变量</SPAN><SPAN
lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US
style="FONT-FAMILY: 'Times New Roman'">x1=0;<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US
style="FONT-FAMILY: 'Times New Roman'">y1=(Form1->Image1->Left+Form1->Image1->Width)/4;<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US
style="FONT-FAMILY: 'Times New Roman'">x2=x1;<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US
style="FONT-FAMILY: 'Times New Roman'">y2=y1;<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US
style="FONT-FAMILY: 'Times New Roman'">Form1->Image1->Canvas->MoveTo((x2),(y2));<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US
style="FONT-FAMILY: 'Times New Roman'">//</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">定义绘图起始点</SPAN><SPAN
lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US
style="FONT-FAMILY: 'Times New Roman'">n=0;<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'">while
(n<3.1415926*6)<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><SPAN
style="mso-spacerun: yes">
</SPAN>{<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><SPAN
style="mso-spacerun: yes">
</SPAN>x2=x2+3.1415926/12;<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><SPAN
style="mso-spacerun: yes">
</SPAN>y2=y1-40*sin(n);<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><SPAN
style="mso-spacerun: yes">
</SPAN>Form1->Image1->Canvas->LineTo((x2),(y2));<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><SPAN
style="mso-spacerun: yes"> </SPAN>//</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">绘制正弦曲线</SPAN><SPAN
lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><SPAN
style="mso-spacerun: yes">
</SPAN>n=n+3.1415926/180;<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><SPAN
style="mso-spacerun: yes"> </SPAN><SPAN
style="mso-spacerun: yes"> </SPAN>}<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US
style="FONT-FAMILY: 'Times New Roman'">}<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US
style="FONT-FAMILY: 'Times New Roman'">//-----------------------------------------------------------------------<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US
style="FONT-FAMILY: 'Times New Roman'"><o:p> </o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'">void
__fastcall TForm1::Image2Click(TObject *Sender)<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US
style="FONT-FAMILY: 'Times New Roman'">{<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'">float
x1;<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'">float
y1;<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'">float
x2;<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'">float
y2;<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'">float
n;<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US
style="FONT-FAMILY: 'Times New Roman'">//</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">定义变量</SPAN><SPAN
lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US
style="FONT-FAMILY: 'Times New Roman'">x1=0;<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US
style="FONT-FAMILY: 'Times New Roman'">y1=(Form1->Image2->Left+Form1->Image2->Width)/4;<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US
style="FONT-FAMILY: 'Times New Roman'">x2=x1;<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US
style="FONT-FAMILY: 'Times New Roman'">y2=y1;<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US
style="FONT-FAMILY: 'Times New Roman'">Form1->Image2->Canvas->MoveTo((x2),(y2));<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US
style="FONT-FAMILY: 'Times New Roman'">//</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">定义绘图起始点</SPAN><SPAN
lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US
style="FONT-FAMILY: 'Times New Roman'">n=0;<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'">while
(n<3.1415926*6)<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><SPAN
style="mso-spacerun: yes">
</SPAN>{<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><SPAN
style="mso-spacerun: yes">
</SPAN>x2=x2+3.1415926/12;<o:p></o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US style="FONT-FAMILY: 'Times New Roman'"><SPAN
style="mso-spacerun: yes">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -