<p><font>//1. 项目下增加相关图片文件夹<br>------------------------------<br>--项目winformstudy<br> --窗体loginform.cs<br> --窗体mainform.cs<br> --文件夹styleimage<br> --子文件夹stylea<br> --相关图片btnadduser.jpg及其他 <br> (将图片做为 嵌入的资源 进行生成) <br> --子文件夹styleb<br> --相关图片btnadduser.jpg及其他 </font></p><p><font>//2. app.config中保存当前窗体的风格<br>------------------------------------<br><?xml version="1.0" encoding="utf-8" ?><br><configuration><br> <appsettings><br> <add key="currentstyle" value="styleb"/><br> </appsettings><br> ...<br></configuration></font></p><p><font>//3. 窗体调用<br>----------------<br>drawstylepicture.drawbuttonbackgroundimage(this.btnadduser, "btnadduser.jpg");</font></p><font><p><br>//4. drawstylepicture<br>-----------------------</p><div class="cnblogs_code"><img id="code_closed_image_110636" height="16" src="http://www.cnblogs.com/images/outliningindicators/contractedblock.gif" width="11" align="top"><img id="code_open_image_110636" style="display: none;" height="16" src="http://www.cnblogs.com/images/outliningindicators/expandedblockstart.gif" width="11" align="top"><span class="cnblogs_code_collapse" id="code_closed_text_110636">code</span><span id="code_open_text_110636" style="display: none;"><br><!--<br /><br />code highlighting produced by actipro codehighlighter (freeware)<br />http://www.codehighlighter.com/<br /><br />--><span style="color: #0000ff;">using</span><span style="color: #000000;">system;<br></span><span style="color: #0000ff;">using</span><span style="color: #000000;">system.collections.generic;<br></span><span style="color: #0000ff;">using</span><span style="color: #000000;">system.text;<br></span><span style="color: #0000ff;">using</span><span style="color: #000000;">system.windows.forms;<br></span><span style="color: #0000ff;">using</span><span style="color: #000000;">system.reflection;<br></span><span style="color: #0000ff;">using</span><span style="color: #000000;">system.drawing;<br></span><span style="color: #0000ff;">using</span><span style="color: #000000;">system.io;<br><br></span><span style="color: #0000ff;">namespace</span><span style="color: #000000;">winformstudy<br>{<br></span><span style="color: #0000ff;">class</span><span style="color: #000000;">drawstylepicture<br>{<br></span><span style="color: #0000ff;">public</span><span style="color: #000000;"></span><span style="color: #0000ff;">static</span><span style="color: #000000;"></span><span style="color: #0000ff;">void</span><span style="color: #000000;">drawformbackgroundimage(objectobj,</span><span style="color: #0000ff;">string</span><span style="color: #000000;">strpicname)<br>{<br>formfrm</span><span style="color: #000000;">=</span><span style="color: #000000;">(form)obj;<br></span><span style="color: #0000ff;">string</span><span style="color: #000000;">strstylename</span><span style="color: #000000;">=</span><span style="color: #000000;">appconfigxmlmanage.getappconfig(</span><span style="color: #800000;">"</span><span style="color: #800000;">currentstyle</span><span style="color: #800000;">"</span><span style="color: #000000;">);<br>assemblyassem</span><span style="color: #000000;">=</span><span style="color: #000000;">assembly.getexecutingassembly();<br>system.io.streamstream</span><span style="color: #000000;">=</span><span style="color: #000000;">assem.getmanifestresourcestream(</span><span style="color: #800000;">"</span><span style="color: #800000;">winformstudy.styleimage.</span><span style="color: #800000;">"</span><span style="color: #000000;"></span><span style="color: #000000;">+</span><span style="color: #000000;">strstylename</span><span style="color: #000000;">+</span><span style="color: #000000;"></span><span style="color: #800000;">"</span><span style="color: #800000;">.</span><span style="color: #800000;">"</span><span style="color: #000000;"></span><span style="color: #000000;">+</span><span style="color: #000000;">strpicname);<br>imageimage</span><span style="color: #000000;">=</span><span style="color: #000000;">bitmap.fromstream(stream);<br>frm.backgroundimage</span><span style="color: #000000;">=</span><span style="color: #000000;">image;<br>frm.backgroundimagelayout</span><span style="color: #000000;">=</span><span style="color: #000000;">imagelayout.stretch;<br>}<br><br></span><span style="color: #0000ff;">public</span><span style="color: #000000;"></span><span style="color: #0000ff;">static</span><span style="color: #000000;"></span><span style="color: #0000ff;">void</span><span style="color: #000000;">drawpanelbackgroundimage(objectobj,</span><span style="color: #0000ff;">string</span><span style="color: #000000;">strpicname)<br>{<br>panelpnl</span><span style="color: #000000;">=</span><span style="color: #000000;">(panel)obj;<br></span><span style="color: #0000ff;">string</span><span style="color: #000000;">strstylename</span><span style="color: #000000;">=</span><span style="color: #000000;">appconfigxmlmanage.getappconfig(</span><span style="color: #800000;">"</span><span style="color: #800000;">currentstyle</span><span style="color: #800000;">"</span><span style="color: #000000;">);<br>assemblyassem</span><span style="color: #000000;">=</span><span style="color: #000000;">assembly.getexecutingassembly();<br>system.io.streamstream</span><span style="color: #000000;">=</span><span style="color: #000000;">assem.getmanifestresourcestream(</span><span style="color: #800000;">"</span><span style="color: #800000;">winformstudy.styleimage.</span><span style="color: #800000;">"</span><span style="color: #000000;"></span><span style="color: #000000;">+</span><span style="color: #000000;">strstylename</span><span style="color: #000000;">+</span><span style="color: #000000;"></span><span style="color: #800000;">"</span><span style="color: #800000;">.</span><span style="color: #800000;">"</span><span style="color: #000000;"></span><span style="color: #000000;">+</span><span style="color: #000000;">strpicname);<br>imageimage</span><span style="color: #000000;">=</span><span style="color: #000000;">bitmap.fromstream(stream);<br>pnl.backgroundimage</span><span style="color: #000000;">=</span><span style="color: #000000;">image;<br>pnl.backgroundimagelayout</span><span style="color: #000000;">=</span><span style="color: #000000;">imagelayout.stretch;<br>}<br><br></span><span style="color: #0000ff;">public</span><span style="color: #000000;"></span><span style="color: #0000ff;">static</span><span style="color: #000000;"></span><span style="color: #0000ff;">void</span><span style="color: #000000;">drawbuttonbackgroundimage(objectobj,</span><span style="color: #0000ff;">string</span><span style="color: #000000;">strpicname)<br>{<br>buttonbtn</span><span style="color: #000000;">=</span><span style="color: #000000;">(button)obj;<br></span><span style="color: #0000ff;">string</span><span style="color: #000000;">strstylename</span><span style="color: #000000;">=</span><span style="color: #000000;">appconfigxmlmanage.getappconfig(</span><span style="color: #800000;">"</span><span style="color: #800000;">currentstyle</span><span style="color: #800000;">"</span><span style="color: #000000;">);<br>assemblyassem</span><span style="color: #000000;">=</span><span style="color: #000000;">assembly.getexecutingassembly();<br>system.io.streamstream</span><span style="color: #000000;">=</span><span style="color: #000000;">assem.getmanifestresourcestream(</span><span style="color: #800000;">"</span><span style="color: #800000;">winformstudy.styleimage.</span><span style="color: #800000;">"</span><span style="color: #000000;"></span><span style="color: #000000;">+</span><span style="color: #000000;">strstylename</span><span style="color: #000000;">+</span><span style="color: #000000;"></span><span style="color: #800000;">"</span><span style="color: #800000;">.</span><span style="color: #800000;">"</span><span style="color: #000000;"></span><span style="color: #000000;">+</span><span style="color: #000000;">strpicname);<br>imageimage</span><span style="color: #000000;">=</span><span style="color: #000000;">bitmap.fromstream(stream);<br>btn.backgroundimage</span><span style="color: #000000;">=</span><span style="color: #000000;">image;<br>btn.backgroundimagelayout</span><span style="color: #000000;">=</span><span style="color: #000000;">imagelayout.stretch;<br>}<br>}<br>}<br><br></span></span>