惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Visual Studio Blog
C
Cisco Blogs
Help Net Security
Help Net Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Scott Helme
Scott Helme
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
M
MIT News - Artificial intelligence
L
LINUX DO - 热门话题
I
InfoQ
GbyAI
GbyAI
NISL@THU
NISL@THU
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Engineering at Meta
Engineering at Meta
H
Hackread – Cybersecurity News, Data Breaches, AI and More
TaoSecurity Blog
TaoSecurity Blog
Simon Willison's Weblog
Simon Willison's Weblog
A
About on SuperTechFans
Spread Privacy
Spread Privacy
月光博客
月光博客
W
WeLiveSecurity
AWS News Blog
AWS News Blog
云风的 BLOG
云风的 BLOG
有赞技术团队
有赞技术团队
Security Latest
Security Latest
人人都是产品经理
人人都是产品经理
PCI Perspectives
PCI Perspectives
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Microsoft Azure Blog
Microsoft Azure Blog
Hugging Face - Blog
Hugging Face - Blog
S
SegmentFault 最新的问题
T
Troy Hunt's Blog
Martin Fowler
Martin Fowler
The Hacker News
The Hacker News
T
Tor Project blog
C
CERT Recently Published Vulnerability Notes
Apple Machine Learning Research
Apple Machine Learning Research
Stack Overflow Blog
Stack Overflow Blog
K
Kaspersky official blog
Cloudbric
Cloudbric
H
Help Net Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
C
Cybersecurity and Infrastructure Security Agency CISA
T
Tailwind CSS Blog
D
DataBreaches.Net
Security Archives - TechRepublic
Security Archives - TechRepublic
T
Tenable Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
博客园 - Franky
L
LINUX DO - 最新话题
MyScale Blog
MyScale Blog

博客园 - xpoint

Sybase 11.0.3 bcp数据报错! Sybase SQL Server 11.0.x 调优方案...(未完成) Windows Server Family 上安装Office 2000 你在使用Gmail,Wallop,MSN Spaces,Three Degrees吗? 网易的邮箱太慢了,还要别的选择吗? 学了学awk,也算是收获 Microsoft PowerToys for Windows XP 给Windows,SCO,AIX添加静态路由 给博客园的bloger提供若干GMail邀请。(暂放半天,明天移帖) 微软的应用程序块列表 了解POP3协议,使用简单的代码监控pop3邮箱,或者不用代码,直接使用telnet 反射的任务 微软为什么把标准提升的这么快, .Net Framework 1.1-> 2.0,连核心的类库都换了! 让你的gVim支持Miscrosoft Visual C++ 2003 得到本机socket选项的全部默认值。 Linux TCP/IP 协议栈源码分析(一) 国外高手参加世界编程大赛时的参赛作品(转载) UltraEdit-32中的小bug。 还是关于《设计模式》
设置一个Label控件上文字的字体样式和字体大小随机的代码
xpoint · 2004-07-11 · via 博客园 - xpoint

在CSDN上有人问如何设置一个Label控件上文字的字体样式和字体大小随机的代码,觉得比较有意思,
    http://community.csdn.net/Expert/topic/3162/3162272.xml?temp=.8220941
随便写了一个,难点在于MSDN上有一段话:
由于 Font 对象是不可变的(意思是说,无法调整它的任何属性),只能给 Font 属性分配一个新 Font 对象。但是,可以使新的字体基于现有字体。其次要使用定时器和随机数。
code:

using System;
using System.IO;
using System.Drawing;
using System.Timers;
using System.Windows.Forms;
namespace SKY.RandLabel
{
    
class App
    
{
        
public static void Main(String[] args)
        
{
            MainForm form 
= new MainForm();
            Application.Run(form);
        }

    }

    
class MainForm : Form
    
{
        
public Random rnd = null;
        
private Label lb1 = null;
        
private Label lb2 = null;
        
public MainForm()
        
{
            
//for test
            string s1 ="";
            
string s2 ="";
            
string s3 ="由于 Font 对象是不可变的(意思是说,无法调整它的任何属性),只能给 Font 属性分配一个新 Font 对象。但是,可以使新的字体基于现有字体。";
            rnd 
= new Random();
            
foreach(string s in Enum.GetNames(typeof(FontStyle)))
            s1
+="  "+s;
            
foreach(int i in Enum.GetValues(typeof(FontStyle)))
            s2
+="  "+System.Convert.ToString(i);
            lb1 
= new Label();
            lb2 
= new Label();
            lb1.BorderStyle 
= BorderStyle.FixedSingle;
            lb1.AutoSize 
= false;
            lb2.Dock 
= DockStyle.Bottom;
            lb1.Dock 
= DockStyle.Fill;
            lb1.Font 
= new Font(lb1.Font, lb1.Font.Style | FontStyle.Bold);
            lb2.AutoSize 
= true;
            
            lb1.Text  
= s3;
            lb2.Text 
= s1;
            
//安装timer
            System.Timers.Timer timer = new System.Timers.Timer(2000);
            timer.Elapsed
+=new ElapsedEventHandler(OnTimedEvent);
            timer.AutoReset 
= true;
            timer.Enabled 
= true;

            Controls.AddRange(
new Control[] {lb1,lb2});
        }

        
public void SetLabelP()
        
{
            FontStyle[] styles 
= (FontStyle[]) Enum.GetValues(typeof(FontStyle));
            
int index = rnd.Next(0,styles.Length);
            
//清除原来得Font属性
            lb1.Font = new Font(lb1.Font, styles[index]);
        }

        
public void OnTimedEvent(object source, ElapsedEventArgs e)
        
{
            SetLabelP();
        }

    }

}

屏幕快照如下: