zoukankan      html  css  js  c++  java
  • 简单label控件 自制

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Windows.Forms;
    using System.Drawing;
    public class MyLabel : Control
    {
     
        protected override void OnPaint(PaintEventArgs e)
        {
            DrawPaint();
            base.OnPaint(e);
        }
        private string showString = "";
        /// <summary>
        /// 显示字符串
        /// </summary>
        public string ShowString
        {
            get { return showString; }
            set { showString = value; 
                     this.Refresh();
                  }
        }
        /// <summary>
        /// 先在缓存内画好
        /// </summary>
        public void DrawPaint()
        {
            Bitmap offBm = new Bitmap(Width, Height);
            Graphics offerSreen = Graphics.FromImage(offBm);//定义画画到图片上
            SolidBrush tempsb = new SolidBrush(Color.White);//定义画笔
            offerSreen.FillRectangle(tempsb, 0, 0, Width, Height);//填充颜色
            tempsb.Color=Color.Black;
            offerSreen.DrawString(showString, this.Font, tempsb, 0, 0);//写文字
            this.CreateGraphics().DrawImage(offBm, 0, 0);//贴出来显示
            offBm.Dispose();//释放
            offerSreen.Dispose();
            tempsb.Dispose();
    
        }
        /// <summary>
        /// 不让重画背景
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPaintBackground(PaintEventArgs e)
        {
            //base.OnPaintBackground(e);
        }
    }
     
  • 相关阅读:
    nginx 启动相关的
    爬取豆瓣读书/文件存储数据/数据库存储数据
    python Web 开发三剑客比较
    scrapy
    爬虫自动登录抽屉
    组合搜索
    html瀑布流
    Ajax上传文件/文件预览
    Form组件
    django分页
  • 原文地址:https://www.cnblogs.com/FuYan/p/4142187.html
Copyright © 2011-2022 走看看