当前位置:网站首页>c# winform panel自定义图片和文字
c# winform panel自定义图片和文字
2022-06-25 06:41:00 【金士顿】
代码下载地址:https://download.csdn.net/download/wojiuguowei/85761936
参考地址:https://stackoverflow.com/questions/10386783/enter-event-not-firing-in-panel-inside-a-usercontrol?answertab=trending#tab-top
public class PanelEx : PictureBox
{
public PanelEx()
{
this.BackColor = Color.Lavender;
pic.BackColor = Color.Blue;
this.GotFocus += new EventHandler(txt_username_GotFocus);
this.LostFocus += new EventHandler(txt_username_LostFocus);
this.Enter += new System.EventHandler(this.CustomEnter);
this.Leave += new System.EventHandler(this.CustomLeave);
this.MouseClick += new System.Windows.Forms.MouseEventHandler(this.CustomMouseClick);
}
private void CustomMouseClick(object sender, MouseEventArgs e)
{
this.Focus();
MessageBox.Show(this.Name + "GetFocus");
this.BackColor = Color.Blue;
}
private void CustomLeave(object sender, EventArgs e)
{
MessageBox.Show(this.Name + "LostFocus");
this.BackColor = Color.Lavender;
}
private void CustomEnter(object sender, EventArgs e)
{
}
PictureBox pic = new PictureBox();
//2、手写像事件方法一样的方法
private void txt_username_GotFocus(object sender, EventArgs e)
{
//获得焦点要执行的代码
}
private void txt_username_LostFocus(object sender, EventArgs e)
{
//失去焦点要执行的代码
}
private static System.Drawing.Image resizeImage(System.Drawing.Image imgToResize, Size size)
{
//获取图片宽度
int sourceWidth = imgToResize.Width;
//获取图片高度
int sourceHeight = imgToResize.Height;
float nPercent = 0;
float nPercentW = 0;
float nPercentH = 0;
//计算宽度的缩放比例
nPercentW = ((float)size.Width / (float)sourceWidth);
//计算高度的缩放比例
nPercentH = ((float)size.Height / (float)sourceHeight);
if (nPercentH < nPercentW)
nPercent = nPercentH;
else
nPercent = nPercentW;
//期望的宽度
int destWidth = (int)(sourceWidth * nPercent);
//期望的高度
int destHeight = (int)(sourceHeight * nPercent);
Bitmap b = new Bitmap(destWidth, destHeight);
Graphics g = Graphics.FromImage((System.Drawing.Image)b);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
//绘制图像
g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);
g.Dispose();
return (System.Drawing.Image)b;
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = e.Graphics;
//g.TranslateTransform(AutoScrollPosition.X, AutoScrollPosition.Y);
Point position = new Point(0, 30);
Font font = new Font("宋体", 10);
g.DrawString("宋体", font, Brushes.Red, position);//第一个参数是 在窗体显示的字符串,第二个是此字符串的字体,第三个是颜色,第四个是输出的起始位置
//position.Y += font.Height + 5; //每输出一个字体后,输出位置向下移
font.Dispose();
//this.AutoScrollMinSize = new Size(350, position.Y + 50);//滚动框
//
Rectangle ObjRct = new Rectangle();
Image ObjImg;
ObjImg = ((Bitmap)Image.FromFile(@"D:\work\develop\开发文档\canopen\测试代码\flowsharp\Plugins\PluginExample\Resources\DefaultImage.png"));
//ObjImg = resizeImage(ObjImg, new Size(this.Width - 20, this.Height - 20));
ObjRct.X = 20;
ObjRct.Y = 20;
ObjRct.Height = this.Height - 40;
ObjRct.Width = this.Width - 40;
g.DrawImage(ObjImg, ObjRct);
}
}
边栏推荐
- Leetcode daily question - 515 Find the maximum value in each tree row
- VOCALOID笔记
- RTKLIB-b33版本中GALILEO广播星历存储问题
- 基于地面点稀少的LiDAR点云的茂密森林蓄积量估算
- Manufacturing process of PCB 2021-10-11
- (tool class) quickly add time to code in source insight
- Runtime——methods成员变量,cache成员变量
- Lebel only wants an asterisk in front of it, but doesn't want to verify it
- Introduction to Sichuan Tuwei ca-is3082w isolated rs-485/rs-422 transceiver
- What if there is no point in data visualization?
猜你喜欢

One "stone" and two "birds", PCA can effectively improve the dilemma of missing some ground points under the airborne lidar forest
![Different paths ii[dynamic planning improvement for DFS]](/img/bb/1e1cee22b9de954de242d299a1a0eb.png)
Different paths ii[dynamic planning improvement for DFS]

NPM install reports an error: gyp err! configure error
![[batch dos-cmd command - summary and summary] - commands related to Internet access and network communication (Ping, Telnet, NSLOOKUP, ARP, tracert, ipconfig)](/img/9b/283d99adf10262c356d1a87ce01bc0.png)
[batch dos-cmd command - summary and summary] - commands related to Internet access and network communication (Ping, Telnet, NSLOOKUP, ARP, tracert, ipconfig)

Evolution of Alibaba e-commerce architecture

Elk + filebeat log parsing, log warehousing optimization, logstash filter configuration attribute

【蒸馏】PointDistiller: Structured Knowledge DistillationTowards Efficient and Compact 3D Detection

VectorDraw Developer Framework 10.10

Full range of isolator chips with integrated isolated power supply

JMeter introduction practice ----- use of global variables and local variables
随机推荐
57. 插入区间
不同路径II[针对DFS的动态规划改进]
Usememo simulation usecallback
One "stone" and two "birds", PCA can effectively improve the dilemma of missing some ground points under the airborne lidar forest
27. 移除元素
Estimation of dense forest volume based on LIDAR point cloud with few ground points
Can I open a stock account with a compass? Is it safe?
[batch dos-cmd command - summary and summary] - commands related to Internet access and network communication (Ping, Telnet, NSLOOKUP, ARP, tracert, ipconfig)
npm install 报错 : gyp ERR! configure error
VectorDraw Web Library 10.10
Vscode official configuration synchronization scheme
【QT】qtcreator便捷快捷键以及QML介绍
搞清信息化是什么,让企业转型升级走上正确的道路
VOCALOID笔记
点云智绘在智慧工地中的应用
单位转换-毫米转像素-像素转毫米
國外LEAD域名郵箱獲取途徑
STL tutorial 4- input / output stream and object serialization
[single chip microcomputer project training] multipoint temperature wireless acquisition system based on nRF905
判断用户是否是第一次进入某个页面