zoukankan      html  css  js  c++  java
  • C# access the embeded resource ,start windows form in console application,list the embeded resources names

    1.Add new folder  Resources in project;

    2.Add resource such as picture in the Resource folder;

    3.Set the picture's Build Action as  Embedded Resource in picture's properties.

    4.Build.

    5.Access the embeded resource fill via assembly and GetManifestResourceStream

    Attention the aforementioned picture's file name must include namespace.folder.filename.ext;such as "ConsoleApp30.Resources.LYF4.jpg"

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Reflection;
    using System.Windows.Forms;
    using System.IO;
    using System.Drawing; 
    
    namespace ConsoleApp30
    {
        class Program
        {
            static System.Windows.Forms.Form fm;
            [STAThread]
            static void Main(string[] args)
            {
                AccessEmbededResources();
                Application.EnableVisualStyles();
                Application.Run(fm);            
                Console.ReadLine();
            }
    
            static void AccessEmbededResources()
            {
                Assembly asm = Assembly.GetExecutingAssembly();
                string fileName = "ConsoleApp30.Resources.LYF4.jpg";           
                using (Stream sm = asm.GetManifestResourceStream(fileName))
                {
                    Image img = System.Drawing.Image.FromStream(sm);
                    fm = new Form();
                    fm.WindowState = FormWindowState.Maximized;
                    fm.FormBorderStyle = FormBorderStyle.Fixed3D;
                    fm.BackgroundImage = img;
                    fm.BackgroundImageLayout = ImageLayout.Zoom;
                    fm.TopMost = true;               
                    fm.Show();
                }
            }
        }
    }
     static void AssemblyGetEmbededResourcesNames()
            {
                Assembly assm = Assembly.GetExecutingAssembly();
                string[] names = assm.GetManifestResourceNames();
                Parallel.ForEach(names, x =>
                {
                    Console.WriteLine(x);
                });
            }
  • 相关阅读:
    ClickHouse之访问权限控制
    ClickHouse之集群搭建以及数据复制
    ClickHouse之简单性能测试
    ClickHouse之初步认识
    从完整备份恢复单个innodb表
    MHA快速搭建
    MySQL 5.7最新版本的2个bug
    Greenplum各种Tips(不定时更新)
    MySQL 5.7贴心参数之binlog_row_image
    TCP窗口机制与流量控制
  • 原文地址:https://www.cnblogs.com/Fred1987/p/13153997.html
Copyright © 2011-2022 走看看