首页 > 其他分享 >再一次体会ResizeRedraw = true;的作用

再一次体会ResizeRedraw = true;的作用

时间:2022-10-16 10:12:11浏览次数:36  
标签:体会 using Height radiobtn new ResizeRedraw Font true chkbox

先放入正常的代码,如下:

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Drawing;
 6 using System.Windows.Forms;
 7 
 8 namespace RadioButtons
 9 {
10     class RadioButtons:Form
11     {
12         bool bFillEllipse;
13         Color colorEllipse;
14         int n = 0;
15 
16         static void Main(string[] args)
17         {
18             Application.Run(new RadioButtons());
19         }
20         public RadioButtons()
21         {
22             Text = "Radio Buttons Demo";
23             ResizeRedraw = true;
24 
25             string[] astrColor = { "Black","Blue","Green","Cyan",
26                                    "Red","Magenta","Yellow","White"};
27             GroupBox grpbox = new GroupBox();
28             grpbox.Parent = this;
29             grpbox.Text = "Color";
30             grpbox.Location = new Point(Font.Height,Font.Height);
31             grpbox.Size = new Size(9 * Font.Height,
32                         (3 * astrColor.Length + 4) * Font.Height/2);
33             for (int i = 0; i < astrColor.Length; i++)
34             {
35                 RadioButton radiobtn = new RadioButton();
36                 radiobtn.Parent = grpbox;
37                 radiobtn.Text = astrColor[i];
38                 radiobtn.Location = new Point(Font.Height,
39                                     3 * (i + 1) * Font.Height/2);
40                 radiobtn.Size = new Size(7 * Font.Height,
41                                          3 * Font.Height/2);
42                 //单选按钮事件
43                 radiobtn.CheckedChanged += new EventHandler(radiobtn_CheckedChanged);
44 
45                 if (i == 0)
46                 {
47                     radiobtn.Checked = true;
48                 }
49             }
50             CheckBox chkbox = new CheckBox();
51             chkbox.Parent = this;
52             chkbox.Text = "Fill Ellipse";
53             chkbox.Location = new Point(Font.Height,
54                               3 * (astrColor.Length + 2) * Font.Height/2);
55             chkbox.Size = new Size(Font.Height * 7,3 * Font.Height/2);
56             chkbox.CheckedChanged += new EventHandler(chkbox_CheckedChanged);
57         }
58 
59         void chkbox_CheckedChanged(object sender, EventArgs e)
60         {
61             bFillEllipse = ((CheckBox)sender).Checked;
62             Invalidate(false);
63             
64         }
65         //单选按钮事件的具体实现
66         void radiobtn_CheckedChanged(object sender, EventArgs e)
67         {
68              RadioButton radiobtn = (RadioButton)sender;
69              if (radiobtn.Checked)
70              {
71                  colorEllipse = Color.FromName(radiobtn.Text);
72                  Invalidate(false);
73                  
74              }
75         }
76         protected override void OnPaint(PaintEventArgs e)
77         {
78              Graphics grfx = CreateGraphics();
79 
80            //测试
81              grfx.DrawString("这是第一行",Font,new SolidBrush(Color.Red),0,n * Font.Height);
82              n++;
83              Console.WriteLine(n);
84 
85              Rectangle rect = new Rectangle(10 * Font.Height,0,
86                                 ClientSize.Width-10*Font.Height-1,
87                                 ClientSize.Height-1);
88              if (bFillEllipse)
89              {
90                  grfx.FillEllipse(new SolidBrush(colorEllipse), rect);
91              }
92              else
93                  grfx.DrawEllipse(new Pen(colorEllipse),rect);
94         }
95     }
96 }

 

 按住界面右下角,间断拖动,可以看到红色字体“这是第一行”和右侧的“椭圆”是随着每次的拖动在不停变化的;

下面尝试将//ResizeRedraw = true;注释掉,看看会发生什么情况 ?代码如下:

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Drawing;
 6 using System.Windows.Forms;
 7 
 8 namespace RadioButtons
 9 {
10     class RadioButtons:Form
11     {
12         bool bFillEllipse;
13         Color colorEllipse;
14         int n = 0;
15 
16         static void Main(string[] args)
17         {
18             Application.Run(new RadioButtons());
19         }
20         public RadioButtons()
21         {
22             Text = "Radio Buttons Demo";
23             //ResizeRedraw = true;
24 
25             string[] astrColor = { "Black","Blue","Green","Cyan",
26                                    "Red","Magenta","Yellow","White"};
27             GroupBox grpbox = new GroupBox();
28             grpbox.Parent = this;
29             grpbox.Text = "Color";
30             grpbox.Location = new Point(Font.Height,Font.Height);
31             grpbox.Size = new Size(9 * Font.Height,
32                         (3 * astrColor.Length + 4) * Font.Height/2);
33             for (int i = 0; i < astrColor.Length; i++)
34             {
35                 RadioButton radiobtn = new RadioButton();
36                 radiobtn.Parent = grpbox;
37                 radiobtn.Text = astrColor[i];
38                 radiobtn.Location = new Point(Font.Height,
39                                     3 * (i + 1) * Font.Height/2);
40                 radiobtn.Size = new Size(7 * Font.Height,
41                                          3 * Font.Height/2);
42                 //单选按钮事件
43                 radiobtn.CheckedChanged += new EventHandler(radiobtn_CheckedChanged);
44 
45                 if (i == 0)
46                 {
47                     radiobtn.Checked = true;
48                 }
49             }
50             CheckBox chkbox = new CheckBox();
51             chkbox.Parent = this;
52             chkbox.Text = "Fill Ellipse";
53             chkbox.Location = new Point(Font.Height,
54                               3 * (astrColor.Length + 2) * Font.Height/2);
55             chkbox.Size = new Size(Font.Height * 7,3 * Font.Height/2);
56             chkbox.CheckedChanged += new EventHandler(chkbox_CheckedChanged);
57         }
58 
59         void chkbox_CheckedChanged(object sender, EventArgs e)
60         {
61             bFillEllipse = ((CheckBox)sender).Checked;
62             Invalidate(false);
63             
64         }
65         //单选按钮事件的具体实现
66         void radiobtn_CheckedChanged(object sender, EventArgs e)
67         {
68              RadioButton radiobtn = (RadioButton)sender;
69              if (radiobtn.Checked)
70              {
71                  colorEllipse = Color.FromName(radiobtn.Text);
72                  Invalidate(false);
73                  
74              }
75         }
76         protected override void OnPaint(PaintEventArgs e)
77         {
78              Graphics grfx = CreateGraphics();
79 
80            //测试
81              grfx.DrawString("这是第一行",Font,new SolidBrush(Color.Red),0,n * Font.Height);
82              n++;
83              Console.WriteLine(n);
84 
85              Rectangle rect = new Rectangle(10 * Font.Height,0,
86                                 ClientSize.Width-10*Font.Height-1,
87                                 ClientSize.Height-1);
88              if (bFillEllipse)
89              {
90                  grfx.FillEllipse(new SolidBrush(colorEllipse), rect);
91              }
92              else
93                  grfx.DrawEllipse(new Pen(colorEllipse),rect);
94         }
95     }
96 }

拖动界面右下角,不断放大,可以看到,“文字”和“椭圆”没有自动刷新,产生了多次重叠。

由此可见,ResizeRedraw = true;的作用就很明显了!

 

 

 

标签:体会,using,Height,radiobtn,new,ResizeRedraw,Font,true,chkbox
From: https://www.cnblogs.com/chenlight/p/16795689.html

相关文章

  • 聊聊技术写作的个人体会
     有群友问过,是什么原因使我开始写技术公众号,又是什么动力让我坚持写的。在我看来,写作是一件不能敷衍的事,通过写作来学习,反而要比单纯地学习的效果要好。为了写成一篇“拿得......
  • 【干货】关于如何提升查找资料的能力,分享下这些年的心得体会
    查找资料也是学习能力的重要组成部分,初学的时候还可以在网上搜到各种资料,各种视频可以学习,随着自己也开始做项目,做开发,懵逼的问题一个接着一个,不仅没有视频可以学习,文档资料......
  • Delete与Truecate table的区别---删除表中所有数据
    一、使用场景与要求:假如现在数据库的某张表中有几千万条数据,要求在最短的时间内删除掉这张表中的所有数据二、区别Delete:1. 是DML(DataManipulateLanguag......
  • python parser.parse_args action=‘store_true‘ 和 ‘store_false’
    store_true就是存储的值为true(store_false就是存储的值为false),用sh命令触发值的设置:parser.add_argument('-p',action='store_true',default=false)#pythontes......
  • 测速工具使用心得体会
    导语:之前写过一个测速小工具,使用的是speedtest-cli提供的api方法,当然除了这个还有其他的测速工具,今天就这个测速工具来说一下使用体验和感受。测速科普测速工具DNS模......
  • 体会
    业务相关 1你当下在做的东西技术栈怎样?其中优缺点?如果从零开始,能不能重新将其实现?2当前系统的使用方是谁?用户量多大?用户集中使用的时间点?3系统落下了哪些数据?这些数......
  • Empire Breakout学习体会
    申明:本文为靶机EMPIRE:BREAKOUT学习笔记,相关操作仅在测试环境中进行,严禁任何危害网络安全的恶意行为。本文主要记录了一些关键知识点,仅供学习!一、安装说明靶机在https://ww......
  • cygwin的下的gcc的一点体会。
    cygwin的下的gcc的一点体会。1,源文件的扩展名为c,按C的规则编译;源文件的扩展名为cpp,按C++的规则编译。注意:两者默认包括的文件也不同。2,gcc-ohe......
  • 从学算法体会如何更好的学习
    一、第一次学习算法记得第一次学习《数据结构和算法》还是在大学的必修课里,是严蔚敏那一版。那个版本的算法跟《算法导论》一样,代码使用的是伪代码。而我们学习的时候,并......
  • Ele_0007:全屏显示 "kiosk": true 模式
    1,c=newo({width:300,height:10,center:true,"kiosk":false,//是否使用kiosk模式。若是使用kiosk模式,应用程......