文件资源,后台调用
- 工程右键【属性】->【资源】->添加文件。
- 右键点击文件选择【属性】->【生成操作】->嵌入资源
- 代码
Assembly assm = Assembly.GetExecutingAssembly(); Stream istr = assm.GetManifestResourceStream("AIP.Resources.SQLStatement.sql"); //AIP是你程序的命名空间,CreateDatabase.Properties 是资源类Resources的命名空间 System.IO.StreamReader sr = new System.IO.StreamReader(istr); string str = sr.ReadLine();
图片资源,Xaml调用
- 工程右键【属性】->【资源】->添加Ico。
- 右键点击文件选择【属性】->【生成操作】->不复制,Resource
<Button Height="59" Width="66" Canvas.Left="66" Canvas.Top="10" Click="StartSignleService_Click">
<Button.OpacityMask>
<ImageBrush ImageSource="Resources/PowerOn.ico"/>
</Button.OpacityMask>
<Button.BorderBrush>
<ImageBrush ImageSource="Resources/PowerOn.ico"/>
</Button.BorderBrush>
<Button.Foreground>
<ImageBrush ImageSource="Resources/PowerOn.ico"/>
</Button.Foreground>
<Button.Background>
<ImageBrush ImageSource="Resources/PowerOn.ico" Stretch="Fill"/>
</Button.Background>
</Button>
图片资源,后台调用
- 工程右键【属性】->【资源】->添加Ico。
- 右键点击文件选择【属性】->【生成操作】->不复制,嵌入的资源
Assembly Resouce = Assembly.GetExecutingAssembly();
Stream StartButtonIconStream = Resouce.GetManifestResourceStream("PanaServiceMonitor.Resources.RedBall.ico");
this.notifyIcon.Icon = new System.Drawing.Icon(YellowBallIconStream);