当前位置:网站首页>C WinForm panel custom picture and text
C WinForm panel custom picture and text
2022-06-25 07:49:00 【Kingston】
Code download address :https://download.csdn.net/download/wojiuguowei/85761936
Reference address :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、 Handwriting is like an event method
private void txt_username_GotFocus(object sender, EventArgs e)
{
// Get focus on the code to execute
}
private void txt_username_LostFocus(object sender, EventArgs e)
{
// Lose focus on the code to execute
}
private static System.Drawing.Image resizeImage(System.Drawing.Image imgToResize, Size size)
{
// Get picture width
int sourceWidth = imgToResize.Width;
// Get the height of the picture
int sourceHeight = imgToResize.Height;
float nPercent = 0;
float nPercentW = 0;
float nPercentH = 0;
// Calculate the scaling of the width
nPercentW = ((float)size.Width / (float)sourceWidth);
// Calculate the scaling of the height
nPercentH = ((float)size.Height / (float)sourceHeight);
if (nPercentH < nPercentW)
nPercent = nPercentH;
else
nPercent = nPercentW;
// The desired width
int destWidth = (int)(sourceWidth * nPercent);
// The height of expectations
int destHeight = (int)(sourceHeight * nPercent);
Bitmap b = new Bitmap(destWidth, destHeight);
Graphics g = Graphics.FromImage((System.Drawing.Image)b);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
// The plot
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(" Song style ", 10);
g.DrawString(" Song style ", font, Brushes.Red, position);// The first parameter is String displayed on the form , The second is the font of this string , The third is color , The fourth is the starting position of the output
//position.Y += font.Height + 5; // After each output of a font , Output position moves down
font.Dispose();
//this.AutoScrollMinSize = new Size(350, position.Y + 50);// Scroll box
//
Rectangle ObjRct = new Rectangle();
Image ObjImg;
ObjImg = ((Bitmap)Image.FromFile(@"D:\work\develop\ Developing documents \canopen\ Test code \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);
}
}
边栏推荐
- Elk + filebeat log parsing, log warehousing optimization, logstash filter configuration attribute
- 用函数的递归来解决几道有趣的题
- 57. 插入区间
- npm install 报错 : gyp ERR! configure error
- Collection of common terms and meanings in forestry investigation based on lidar
- Misunderstanding of switching triode
- OAuth 2.0 one click login
- C# 读取web上的xml
- STL tutorial 4- input / output stream and object serialization
- Audio (V) audio feature extraction
猜你喜欢

Requirements for Power PCB circuit board design 2021-11-09

一“石”二“鸟”,PCA有效改善机载LiDAR林下地面点部分缺失的困局

opencv最小值滤波(不局限于图像)

GUI pull-down menu of unity3d evil door implementation dropdown design has no duplicate items

SCM Project Training

STL tutorial 4- input / output stream and object serialization

函数模板_类模板

(tool class) use SecureCRT as the communication medium

"Spatial transformation" significantly improves the quality of ground point extraction of cliff point cloud

China Mobile MCU product information
随机推荐
SSL证书免费获取教程
[batch dos-cmd command - summary and summary] - file and directory operation commands (MD, RD, xcopy, dir, CD, set, move, copy, del, type, sort)
对链表进行插入排序[dummy统一操作+断链核心--被动节点]
国外LEAD域名邮箱获取途径
年后求职找B端产品经理?差点把自己坑惨了......
navicat定时任务无效
Three years of continuous decline in revenue, Tiandi No. 1 is trapped in vinegar drinks
【QT】Qt 5 的程序:打印文档
NSIS silent installation vs2013 runtime
PCB board design - automatic layout 2021-10-15
Bicubic difference
Storage of Galileo broadcast ephemeris in rtklib-b33
函数模板_类模板
Chuantu microelectronics ca-if1051 can-fd transceiver
Application of point cloud intelligent drawing in intelligent construction site
一“石”二“鸟”,PCA有效改善机载LiDAR林下地面点部分缺失的困局
Sichuan Tuwei ca-if1051 can transceiver has passed aec-q100 grade 1 certification
ELK + filebeat日志解析、日志入库优化 、logstash过滤器配置属性
test
Manufacturing process of PCB 2021-10-11