⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 c++ builder 程序设计实用教程 - 2_2 颜色调节组件 - 张晋 - 17xie.htm

📁 已经消失的不易找到的C++ builder网络教程总结
💻 HTM
📖 第 1 页 / 共 4 页
字号:
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">“前景选定”按钮(组件</SPAN><SPAN 
lang=EN-US>Button1</SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">):在程序运行的过程中动态的设置文本输入框的前景色,即组件中文本的显示颜色;</SPAN></P>
<P class=MsoNormal 
style="MARGIN-LEFT: 42.5pt; TEXT-INDENT: -21.25pt; tab-stops: list 21.25pt 42.0pt; mso-list: l0 level1 lfo1"><SPAN 
lang=EN-US 
style="FONT-FAMILY: Wingdings; mso-fareast-font-family: Wingdings; mso-bidi-font-family: Wingdings"><SPAN 
style="mso-list: Ignore">n<SPAN 
style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
</SPAN></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>Button2</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=a1><SPAN lang=EN-US>void __fastcall TForm1::Button1Click(TObject 
*Sender)</SPAN></P>
<P class=a1><SPAN lang=EN-US>{</SPAN></P>
<P class=a1><SPAN 
lang=EN-US>Form1-&gt;Memo1-&gt;Font-&gt;Color=Form1-&gt;CColorGrid1-&gt;ForegroundColor;</SPAN></P>
<P class=a1><SPAN lang=EN-US>//</SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">设置文本框的前景色</SPAN></P>
<P class=a1><SPAN lang=EN-US>}</SPAN></P>
<P class=a1><SPAN 
lang=EN-US>//-----------------------------------------------------------------------</SPAN></P>
<P class=a1><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US>void __fastcall TForm1::Button2Click(TObject 
*Sender)</SPAN></P>
<P class=a1><SPAN lang=EN-US>{</SPAN></P>
<P class=a1><SPAN 
lang=EN-US>Form1-&gt;Memo1-&gt;Color=Form1-&gt;CColorGrid1-&gt;BackgroundColor;</SPAN></P>
<P class=a1><SPAN lang=EN-US>//</SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">设置文本框的背景色</SPAN></P>
<P class=a1><SPAN lang=EN-US>}</SPAN></P>
<P class=a1><SPAN 
lang=EN-US>//-----------------------------------------------------------------------</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>Memo1</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>3</SPAN><SPAN 
style="FONT-FAMILY: 楷体_GB2312; mso-ascii-font-family: 'Times New Roman'">.响应</SPAN><SPAN 
lang=EN-US>CColorGrid</SPAN><SPAN 
style="FONT-FAMILY: 楷体_GB2312; mso-ascii-font-family: 'Times New Roman'">事件</SPAN></H4>
<P class=MsoNormalIndent style="MARGIN: 2pt 0cm"><SPAN 
lang=EN-US>CColorGrid</SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">组件的功能是在程序运行的过程中,为文本框组件提供调节颜色的容器,在程序设计的过程中,用鼠标的左键双击</SPAN><SPAN 
lang=EN-US>CColorGrid</SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">组件,在弹出的代码窗口中添加如下所示的</SPAN><SPAN 
lang=EN-US>CColorGrid</SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">组件响应代码:</SPAN></P>
<P class=a1><SPAN lang=EN-US>void __fastcall TForm1::CColorGrid1Change(TObject 
*Sender)</SPAN></P>
<P class=a1><SPAN lang=EN-US>{</SPAN></P>
<P class=a1><SPAN 
lang=EN-US>Form1-&gt;Memo1-&gt;Font-&gt;Color=Form1-&gt;CColorGrid1-&gt;ForegroundColor;</SPAN></P>
<P class=a1><SPAN 
lang=EN-US>Form1-&gt;Memo1-&gt;Color=Form1-&gt;CColorGrid1-&gt;BackgroundColor;</SPAN></P>
<P class=a1><SPAN lang=EN-US>//</SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">随时更改文本框的颜色设置</SPAN></P>
<P class=a1><SPAN lang=EN-US>}</SPAN></P>
<P class=a1><SPAN 
lang=EN-US>//-----------------------------------------------------------------------</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 style="MARGIN: 3pt 0cm"><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在程序运行的过程中,当用户用鼠标单击</SPAN><SPAN 
lang=EN-US>CColorGrid</SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">组件时,就会激活</SPAN><SPAN 
lang=EN-US>CColorGrid1Change</SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">事件,</SPAN><SPAN 
lang=EN-US>CColorGrid</SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">组件会自动判断用户单击鼠标左键还是鼠标右键,如果是鼠标左键单击</SPAN><SPAN 
lang=EN-US>CColorGrid</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-&gt;Memo1-&gt;Font-&gt;Color 
=Form1-&gt;CColorGrid1-&gt;ForegroundColor;</SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">语句来设置</SPAN><SPAN 
lang=EN-US>Memo1</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-&gt;Memo1-&gt;Color=Form1-&gt;CColorGrid1-&gt; 
BackgroundColor</SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">;来设置</SPAN><SPAN 
lang=EN-US>Memo1</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><SPAN 
lang=EN-US>CheckBox</SPAN><SPAN 
style="FONT-FAMILY: 楷体_GB2312; mso-ascii-font-family: 'Times New Roman'">组件</SPAN></H4>
<P class=MsoNormalIndent><SPAN lang=EN-US>CheckBox</SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">组件的功能是在程序运行的过程中,为</SPAN><SPAN 
lang=EN-US>Memo1</SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">组件提供一个随机的文本显示前景色和背景色,为此在程序设计的过程中,用鼠标的左键双击相应的</SPAN><SPAN 
lang=EN-US>CheckBox</SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">组件,在弹出的代码窗口中添加如下所示的响应代码:</SPAN></P>
<P class=a1><SPAN lang=EN-US>void __fastcall TForm1::CheckBox1Click(TObject 
*Sender)</SPAN></P>
<P class=a1><SPAN lang=EN-US>{</SPAN></P>
<P class=a1><SPAN lang=EN-US>if (Form1-&gt;CheckBox1-&gt;Checked)</SPAN></P>
<P class=a1><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; 
</SPAN>Form1-&gt;Memo1-&gt;Font-&gt;Color=RGB(random(255),random(255),random(255));</SPAN></P>
<P class=a1><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; 
</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>Memo</SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">组件中以随机前景色显示文本</SPAN></P>
<P class=a1><SPAN lang=EN-US>}</SPAN></P>
<P class=a1><SPAN 
lang=EN-US>//-----------------------------------------------------------------------</SPAN></P>
<P class=a1><SPAN lang=EN-US><o:p>&nbsp;</o:p></SPAN></P>
<P class=a1><SPAN lang=EN-US>void __fastcall TForm1::CheckBox2Click(TObject 
*Sender)</SPAN></P>
<P class=a1><SPAN lang=EN-US>{</SPAN></P>
<P class=a1><SPAN lang=EN-US>if (Form1-&gt;CheckBox2-&gt;Checked)</SPAN></P>
<P class=a1><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; 
</SPAN>Form1-&gt;Memo1-&gt;Color=RGB(random(255),random(255),random(255));</SPAN></P>
<P class=a1><SPAN lang=EN-US><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; 
</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>Memo</SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">组件中显示随机背景色</SPAN></P>
<P class=a1><SPAN lang=EN-US>}</SPAN></P>
<P class=a1><SPAN 
lang=EN-US>//-----------------------------------------------------------------------</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 style="MARGIN: 6pt 0cm"><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">在程序运行的过程中,如果用户单击</SPAN><SPAN 
lang=EN-US>CheckBox</SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">组件,就会激活相应的</SPAN><SPAN 
lang=EN-US>CheckBox1Click</SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">事件或</SPAN><SPAN 
lang=EN-US>CheckBox2Click</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><SPAN 
lang=EN-US>CheckBox</SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">组件的选中状态,如果处于选中状态,那么就会通过语句</SPAN></P>
<P class=MsoNormalIndent style="MARGIN: 2pt 0cm"><SPAN 
lang=EN-US>Form1-&gt;Memo1-&gt;Font-&gt;Color=RGB(random(255)</SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">,</SPAN><SPAN 
lang=EN-US>random(255)</SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">,</SPAN><SPAN 
lang=EN-US>random(255))</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><SPAN 
lang=EN-US>Memo</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 
lang=EN-US>Form1-&gt;Memo1-&gt;Color=RGB(random(255)</SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">,</SPAN><SPAN 
lang=EN-US>random(255)</SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">,</SPAN><SPAN 
lang=EN-US>random(255))</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><SPAN 
lang=EN-US>Memo</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>5</SPAN><SPAN 
style="FONT-FAMILY: 楷体_GB2312; mso-ascii-font-family: 'Times New Roman'">.运行程序</SPAN></H4>
<P class=MsoNormalIndent style="MARGIN: 3pt 0cm"><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></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>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>2-6</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=288 
src="C++ Builder 程序设计实用教程 - 2_2 颜色调节组件 - 张晋 - 17xie.files/7ba6b5fbf9.jpg" 
width=302 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>2-6<SPAN style="mso-spacerun: yes">&nbsp; </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><SPAN 
lang=EN-US>CColorGrid</SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">组件上选择文本框的前景色和背景色,还可以用随机颜色来设置</SPAN><SPAN 
lang=EN-US>Memo1</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><SPAN 
lang=EN-US>2-7</SPAN><SPAN 
style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">所示。</SPAN></P>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -