[Tool]纯代码绘制提示框

本文介绍了一种绘制屏幕中心提示界面的方法,包括不同类型的提示图标及其布局。该方法使用了特定的坐标和尺寸来确保提示框的正确显示,并根据不同类型的提示调整了文字的位置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 /**
  * 绘制提示界面(屏幕中心提示框120*90)
  *
  * @param img提示图片
  * @param cueType提示类型(0邮件,1删除,2等待,3错误)
  * @param SCREEN_WIDTH屏幕宽度
  * @param SCREEN_HEIGHT屏幕高度
  * @param g
  */
 public static void drawCueCanvas(Image img, int cueType, String[] cueStr,
   int SCREEN_WIDTH, int SCREEN_HEIGHT, boolean type, Graphics g) {
  // 当前提示图片数量为4;
  int imgWidth = img.getWidth() / 4;
  int imgHeight = img.getHeight();
  // 28
  int top_x = SCREEN_WIDTH / 2 - 120 / 2;
  // 59
  int top_y = SCREEN_HEIGHT / 2 - 90 / 2;
  // 绘制黑色边框
  g.setColor(0);
  g.drawLine(top_x + 5, top_y, top_x + 120 - 5, top_y);
  g.drawLine(top_x + 2, top_y + 1, top_x + 120 - 2, top_y + 1);
  g.drawLine(top_x + 1, top_y + 2, top_x + 120 - 1, top_y + 2);
  g.drawLine(top_x + 1, top_y + 3, top_x + 120 - 1, top_y + 3);
  // 中间
  g.fillRect(top_x, top_y + 4, 120, 90 - 8);
  // 下端
  g.drawLine(top_x + 5, top_y + 90, top_x + 120 - 5, top_y + 90);
  g.drawLine(top_x + 2, top_y + 89, top_x + 120 - 2, top_y + 89);
  g.drawLine(top_x + 1, top_y + 88, top_x + 120 - 1, top_y + 88);
  g.drawLine(top_x + 1, top_y + 87, top_x + 120 - 1, top_y + 87);
  g.drawLine(top_x + 1, top_y + 86, top_x + 120 - 1, top_y + 86);
  // 黄色框
  g.setColor(0xFFCC00);
  g.drawLine(top_x + 4, top_y + 1, top_x + 120 - 4, top_y + 1);
  g.drawLine(top_x + 2, top_y + 2, top_x + 120 - 3, top_y + 2);
  g.drawLine(top_x + 1, top_y + 4, top_x + 1, top_y + 90 - 4);
  g.drawLine(top_x + 2, top_y + 2, top_x + 2, top_y + 90 - 3);
  // 绘制中心黄框
  g.setColor(0xFFFFDD);
  g.fillRect(top_x + 3, top_y + 3, 114, 84);
  g.setColor(0);
  if (type) {
   for (int i = 0; i < cueStr.length; i++) {
    g.drawString(cueStr[i], top_x + 50, top_y + 20 + i
      * MainCanvas.FONT_HEIGHT, Graphics.TOP | Graphics.LEFT);
   }
   g.setClip(top_x + 10, top_y + 10, imgWidth, imgHeight);
   // 绘制图片
   g.drawImage(img, top_x + 10 - cueType * imgWidth, top_y + 10,
     Graphics.TOP | Graphics.LEFT);
  } else {
   for (int i = 0; i < cueStr.length; i++) {
    g.drawString(cueStr[i], top_x + 60, top_y + 65 + i
      * MainCanvas.FONT_HEIGHT, Graphics.BASELINE
      | Graphics.HCENTER);
   }
   g.setClip(top_x + 60 - 20, top_y + 10, imgWidth, imgHeight);
   // 绘制图片
   g.drawImage(img, top_x + 60 - 20 - cueType * imgWidth, top_y + 10,
     Graphics.TOP | Graphics.LEFT);
  }
  g.setClip(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
 } 
Imports System.ComponentModel _ Public Class DSButton Private _ButtonColor As Color = Color.White Private SF As New System.Drawing.StringFormat Private _Text As String Public Property ButtonColor As Color Get Return _ButtonColor End Get Set(ByVal value As Color) _ButtonColor = value MakeRoundedRect(RoundRectValue, Me, Color.FromArgb(255, ButtonColor.R / 255 * 50, ButtonColor.G / 255 * 50, ButtonColor.B / 255 * 50)) End Set End Property Public Property RoundRectValue As Integer = 10 Private nIndex As Integer = 0 Private IsMouseEnter As Boolean = False Public Property IsShowAnimate As Boolean = False Public Property ButtonText As String Get Return _Text End Get Set(ByVal value As String) _Text = value MakeRoundedRect(RoundRectValue, Me, Color.FromArgb(255, ButtonColor.R / 255 * 50, ButtonColor.G / 255 * 50, ButtonColor.B / 255 * 50)) End Set End Property Private _TextColor As Color = Color.White Public Property TextColor As Color Get Return _TextColor End Get Set(ByVal value As Color) _TextColor = value MakeRoundedRect(RoundRectValue, Me, Color.FromArgb(255, ButtonColor.R / 255 * 50, ButtonColor.G / 255 * 50, ButtonColor.B / 255 * 50)) End Set End Property Private Sub DSButton_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load SetStyle(ControlStyles.UserPaint, True) SetStyle(ControlStyles.AllPaintingInWmPaint, True) SetStyle(ControlStyles.ResizeRedraw, True) SetStyle(ControlStyles.Selectable, True) SF.LineAlignment = StringAlignment.Center SF.Alignment = StringAlignment.Center MakeRoundedRect(RoundRectValue, Me, Color.FromArgb(255, ButtonColor.R / 255 * 50, ButtonColor.G / 255 * 50, ButtonColor.B / 255 * 50)) End Sub Private Sub MakeRoundedRect(ByVal Rounded As Integer, ByVal Ct As Control, ByVal ButtonColor As Color) If Ct.BackgroundImage IsNot Nothing Then Ct.BackgroundImage.Dispose() Ct.BackgroundImage = New Bitmap(Ct.Width, Ct.Height) Dim WW, HH As Integer WW = Ct.Width - 1 HH = Ct.Height - 1 Using G As Graphics = Graphics.FromImage(Ct.BackgroundImage) G.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias G.TextRenderingHint = Drawing.Text.TextRenderingHint.ClearTypeGridFit Using Gp As New Drawing2D.GraphicsPath Gp.AddArc(New Rectangle(0, 0, Rounded, Rounded), 180, 90) Gp.AddArc(New Rectangle(WW - Rounded, 0, Rounded, Rounded), -90, 90) Gp.AddArc(New Rectangle(WW - Rounded, HH - Rounded, Rounded, Rounded), 0, 90) Gp.AddArc(New Rectangle(0, HH - Rounded, Rounded, Rounded), 90, 90) Gp.AddLine(New Point(0, HH - Rounded), New Point(0, Rounded / 2)) Using Lg As New Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(0, HH), ControlPaint.Dark(ButtonColor, 0.5), ButtonColor) G.FillPath(Lg, Gp) G.DrawPath(Pens.Black, Gp) End Using End Using WW = WW - 3 HH = HH - 3 Using Gp As New Drawing2D.GraphicsPath Gp.AddArc(New Rectangle(3, 3, Rounded, Rounded), 180, 90) Gp.AddArc(New Rectangle(WW - Rounded, 3, Rounded, Rounded), -90, 90) Gp.AddArc(New Rectangle(WW - Rounded, HH / 2 - Rounded - 1, Rounded, Rounded), 0, 90) Gp.AddArc(New Rectangle(3, HH / 2 - Rounded - 1, Rounded, Rounded), 90, 90) Using Lg As New Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(0, HH / 2), Color.FromArgb(220, 255, 255, 255), Color.FromArgb(50, 255, 255, 255)) G.FillPath(Lg, Gp) End Using End Using Using Gp As New Drawing2D.GraphicsPath Gp.AddEllipse(New Rectangle(3, HH / 2 + 10, WW, HH / 2)) Using Lg As New Drawing2D.PathGradientBrush(Gp) Lg.CenterColor = Color.FromArgb(150, 255, 255, 255) Lg.SurroundColors = New Color() {Color.Transparent} Gp.FillMode = Drawing2D.FillMode.Winding G.FillPath(Lg, Gp) End Using End Using Try If _Text.Length 0 Then G.DrawString(_Text, Me.Font, New SolidBrush(TextColor), New Rectangle(0, 0, Me.Width, Me.Height), SF) Catch End Try End Using End Sub Private Sub DSButton_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick End Sub Private Sub DSButton_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown If e.Button = MouseButtons.Left Then MakeRoundedRect(RoundRectValue, Me, Color.Black) End If End Sub Private Sub DSButton_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseEnter If DesignMode = False Then IsMouseEnter = True Timer1.Enabled = True End If End Sub Private Sub DSButton_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseLeave If DesignMode = False Then IsMouseEnter = False Timer1.Enabled = True End If End Sub Private Sub DSButton_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp MakeRoundedRect(RoundRectValue, Me, _ButtonColor) End Sub Private Sub DSButton_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SizeChanged If Me.IsHandleCreated Then MakeRoundedRect(RoundRectValue, Me, ButtonColor) End If End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Select Case IsMouseEnter Case True If IsShowAnimate = True Then nIndex = IIf(nIndex + 30 >= 225, 255, nIndex + 30) If nIndex >= 255 Then Timer1.Enabled = False Else nIndex = 255 Timer1.Enabled = False End If Case False nIndex = IIf(nIndex - 20 <= 50, 50, nIndex - 20) If nIndex <= 50 Then Timer1.Enabled = False End Select Try MakeRoundedRect(RoundRectValue, Me, Color.FromArgb(255, ButtonColor.R / 255 * nIndex, ButtonColor.G / 255 * nIndex, ButtonColor.B / 255 * nIndex)) Catch End Try End Sub End Class
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值