通过控件 C# 绘制和清除字符串

发布于 2024-11-17 21:07:58 字数 247 浏览 2 评论 0原文

经过谷歌搜索后,我得到了一些例子,但没有一个给我我需要的东西。

我需要在 ButtonClick 上将一个字符串 (WriteString()) 写入 WinForm 中的控件中,并且我需要更新该绘图,因为我正在尝试写入日期进入控件,系统日期。

因此,每次用户单击该按钮时,DateTime.Now.ToString(); 都应该被绘制到控件中。

最好的

After some search at Google I had some examples but none of them gave me what I need.

I need to write a String (WriteString()) into a Control in WinForm on a ButtonClick and I need to update that Draw, because i'm trying to write the Date into the Control, the System Date.

So each time the user clicks on that Button the DateTime.Now.ToString(); should be drawn into the Control.

Bests

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

月竹挽风 2024-11-24 21:07:58

在标签上绘制字符串

url 肯定会对你有帮助,

那里写的代码是

void Label_OnPaint(object sender, PaintEventArgs e) {
  base.OnPaint(e);
  Label lbl = sender as Label;
  if (lbl != null) {
    string Text = lbl.Text;
    e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
    if (myShowShadow) { // draw the shadow first!
      e.Graphics.DrawString(Text, lbl.Font, new SolidBrush(myShadowColor), myShadowOffset, StringFormat.GenericDefault);
    }
    e.Graphics.DrawString(Text, lbl.Font, new SolidBrush(lbl.ForeColor), 0, 0, StringFormat.GenericDefault);
  }
}

draw a string on label

this url will surely help you

the code written there is

void Label_OnPaint(object sender, PaintEventArgs e) {
  base.OnPaint(e);
  Label lbl = sender as Label;
  if (lbl != null) {
    string Text = lbl.Text;
    e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
    if (myShowShadow) { // draw the shadow first!
      e.Graphics.DrawString(Text, lbl.Font, new SolidBrush(myShadowColor), myShadowOffset, StringFormat.GenericDefault);
    }
    e.Graphics.DrawString(Text, lbl.Font, new SolidBrush(lbl.ForeColor), 0, 0, StringFormat.GenericDefault);
  }
}
旧竹 2024-11-24 21:07:58

您应该考虑使用 winforms Label计时器

You should consider using a winforms Label and a Timer for that.

单调的奢华 2024-11-24 21:07:58

或者您可以修改控件的 OnPaint 方法来覆盖控件的绘制方式。 Graphics 对象中有一个方法可以让你写一个字符串 g.DrawString

Or you could modify the OnPaint method of the control to override how the control is painted. There is a method in the Graphics object that lets you write a string g.DrawString

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文