当前位置:网站首页>C#WinForm开发:如何将图片添加到项目资源文件(Resources)中
C#WinForm开发:如何将图片添加到项目资源文件(Resources)中
2022-07-28 02:22:00 【黄昏和星空】
C#WinForm开发:如何将图片添加到项目资源文件(Resources)中
引言
操作步骤
实例应用
功能延展
引言
在C#Winform开发中,有时需要在控件中插入一些图片,常见的有pictureBox控件的Image属性。那么,我们应当如何将现有图片添加到项目资源文件中?操作步骤
在VS 2017中新建一个“Windows窗体应用”项目,然后保存两张图片到桌面。这里,项目名称为“cyTest”,图片名称为“JapaneseBoy”和“WhiteBoard”,至此准备工作完成。
在“解决方案资源管理器”视图中,双击“Properities -> Resources.resx”选项:
在弹出的“Resources.resx”窗口中,单击"添加资源"选项后的“倒三角”图标。然后,在出现的下拉菜单中,单击"添加现有文件"选项:
找到图片保存路径,选中两张图片,单击“打开”按钮即可:
“解决方案资源管理器”视图中“cyTest”项目下,自动生成“Resources”文件夹及已添加的两张图片。至此,已成功将图片添加至项目资源文件中。
实例应用
以在Form中插入两个图片为例:
在Form中拖放两个pictureBox控件:
编写如下程序代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace cyTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Image cyImage1, cyImage2;
private void Form1_Load(object sender, EventArgs e)
{
cyImage1 = Properties.Resources.JapaneseBoy;
pictureBox1.Image = cyImage1;
pictureBox1.Height = cyImage1.Height;
pictureBox1.Width = cyImage1.Width;
pictureBox1.Location = new Point(10, 10);
cyImage2 = Properties.Resources.WhiteBoard;
pictureBox2.Image = cyImage2;
pictureBox2.Height = cyImage2.Height;
pictureBox2.Width = cyImage2.Width;
pictureBox2.Location = new Point(700, 10);
}
}
}
边栏推荐
- trivy【1】工具扫描运用
- 基于JSP&Servlet实现的众筹平台系统
- els 定时器
- stm32F407-------DSP学习
- CNN training cycle reconstruction - hyperparametric test | pytorch series (XXVIII)
- 微服务架构统一安全认证设计与实践
- Trivy [1] tool scanning application
- 【2022 牛客第二场J题 Link with Arithmetic Progression】三分套三分/三分极值/线性方程拟合最小二乘法
- Docker advanced -redis cluster configuration in docker container
- Where do I go to open an account for stock speculation? Is it safe to open an account on my mobile phone
猜你喜欢

Original title of Blue Bridge Cup

JS event object 2 e.charcode character code e.keycode key code box moves up, down, left and right

微服务架构统一安全认证设计与实践

QFileDevice、QFile、QSaveFile、QTemporaryFile

CNN循环训练的解释 | PyTorch系列(二十二)

ECCV 2022 | open source for generative knowledge distillation of classification, detection and segmentation

Stop paging with offset and limit. The performance is too poor!

Docker advanced -redis cluster configuration in docker container

每日刷题巩固知识

Is it you who are not suitable for learning programming?
随机推荐
上位机与MES对接的几种方式
Oracle basicfile lob field space recycling shrink space doubts
Development and design logic of rtsp/onvif protocol easynvr video platform one click upgrade scheme
谈一谈百度 科大讯飞 云知声的语音合成功能
Design and practice of unified security authentication for microservice architecture
What "posture" does JD cloud have to promote industrial digitalization to climb to a "new level"?
Niuke-top101-bm340
Where do I go to open an account for stock speculation? Is it safe to open an account on my mobile phone
Day 8 of DL
Data Lake: database data migration tool sqoop
exness:日本物价上涨收入下降,英镑/日元突破 165
Unexpected harvest of epic distributed resources, from basic to advanced are full of dry goods, big guys are strong!
注意,这些地区不能参加7月NPDP考试
【2022牛客多校2 K Link with Bracket Sequence I】括号线性dp
ROS的调试经验
@Valid的作用(级联校验)以及常用约束注解的解释说明
四、固态硬盘存储技术的分析(论文)
WEB安全基础 - - -命令执行漏洞
意外收获史诗级分布式资源,从基础到进阶都干货满满,大佬就是强!
会议OA项目之我的审批&&签字功能