form的Paint事件执行以下代码:

WINFORM学习手册——绘制简单图像

/// <summary>
        /// 画一段话和一个方块
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SimpleImgForm_Paint(object sender, PaintEventArgs e)
        {
            //画字
            var grap = e.Graphics;//获取画布
            grap.PageUnit = GraphicsUnit.Millimeter;//设置长度单位为毫米
            var font = new Font("宋体", 20, GraphicsUnit.Point);//设置字体
            var brush = new SolidBrush(Color.Blue);//设置字体填充色
            grap.DrawString("测试用字符串", font, brush, 50, 50);//在画布上划伤“测试用字符串”几个字
            //画方块
            grap.DrawRectangle(new Pen(Color.Red), new Rectangle(10, 10, 20, 20));
        }

执行效果:

WINFORM学习手册——绘制简单图像

注:绘图时,默认单位是px,可以通过grap.PageUnit = GraphicsUnit.Millimeter修改

相关文章:

  • 2021-12-28
  • 2022-12-23
  • 2022-01-27
  • 2021-12-31
  • 2019-02-15
  • 2021-10-19
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-09-22
  • 2022-12-23
  • 2021-11-05
  • 2021-11-05
  • 2021-05-24
相关资源
相似解决方案