Set the font styles of the text on the Label control and the font size random code.

zhaozj2021-02-16  65

Someone on 9CBS asks how to set up a font style and font size random code on the Label control, feel more interesting, http://community.9cbs.net/expert/topic/3162/3162272.xml?temp =.8220941 Just write one, the difficulty is that there is a paragraph on the MSDN: Since the Font object is unstrenomed (meaning, any property that cannot be adjusted), you can only assign a new Font object to the Font property. However, the new font can be based on existing fonts. Second, use timers and random numbers. 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} class mainform: form {public random rnd = null; private labl lb1 = null; private label lb2 = null; public mainform () {// for test string s1 = "; string S2 = ""; String S3 = "Since the font object is constant (meaning, any attribute that cannot be adjusted) can only assign a new FONT object to the Font property. However, the new font can make the new font based on the existing Font. "; RND = new random (); foreach (string s in enum.getnames) S1 =" " S; Foreach (INTSTYLE)) 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.tex Timer system.timers.timer timer system.timers.timer time = new system.timers.timer (2000); Timer.EventHand = New ElapSedEventHandler (Timer.AutoreSet = true; Timer.enabled = true;

Controls.addrange (new control [] {lb1, lb2});} public void setLabelp () {fontstyle [] style = (fontstyle []) ENUM.GETVALUES (INDEOF (FontStyle)); int index = rnd.next (0 STYLES.LENGTH); / / Clear the original FONT attribute lb1.font = new font (lb1.font, styles [index]);} public void ontimedEvent (Object Source, ElapSedEventArgs E) {setLabelp ();}}} -------------------------------------------------- --------------------

Screen snapshot:

转载请注明原文地址:https://www.9cbs.com/read-17149.html

New Post(0)